﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ZG_member.BLL;
using System.IO;
using VisualCardPrinter_NPPrinter;
using System.Configuration;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Net;

namespace ZG_member
{
    public partial class MemberSaleForm : Form
    {
        public VisualCardPrinter_NPPrinter_New.VisualCardPrinter_NPPrinter vnp;
        MainForm mainfrom;
        string id = "0";
        string memberId = "0";
        public MemberSaleForm(MainForm main, string id1,string memberIds, VisualCardPrinter_NPPrinter_New.VisualCardPrinter_NPPrinter VNp)
        {
            InitializeComponent();
            mainfrom = main;
            vnp = VNp;
            id = id1;
            memberId = memberIds;
            skinEngine1.SkinFile = Application.StartupPath + ConfigurationManager.AppSettings["Skin"];

        }
        //public MemberSaleForm(MainForm main,VisualCardPrinter_NPPrinter_New.VisualCardPrinter_NPPrinter VNp,string memid)
        //{
        //    InitializeComponent();
        //    mainfrom = main;
        //    vnp = VNp;
        //    memberId = memid;
        //    skinEngine1.SkinFile = Application.StartupPath + ConfigurationManager.AppSettings["Skin"];

        //}

        int ret;
        string Integral = "";
        public static string userName;
        int dayincishu = 1;
        string memberID = "";
        //抵用卷金额时使用的变量
        public double Changeprice = 0;
        //提成价钱计算
        public double tichengMoney = 0;
        public bool test(Model.memberInfo membMod)
        {
            Model.memberInfo memberMod = new Model.memberInfo();
            memberMod = membMod;
            if (memberMod.statusStr != null)
            {
                if (memberMod.statusStr != "正常")
                {
                    //MessageBox.Show("您的卡已无法使用！");
                    return false;
                }
            }
            if (memberMod.status != null)
            {
                if (memberMod.status != 0)
                {
                    //MessageBox.Show("您的卡已无法使用！");
                    return false;
                }
            }

            DateTime over = DateTime.Now;
            DateTime now = (DateTime)memberMod.expiresDate;
            if (now <= over)
            {
                memberInfo m = new memberInfo();
                wasteBook wast = new wasteBook();
                string status = "2";
                memberMod.point = 0;
                if (m.Updatepoint(memberMod))
                {
                    wast.Updatepoint(memberMod.memberId);
                }

                m.Update3(status, memberMod.memberId);
                //MessageBox.Show("您的卡已过期！");
                return false;
            }
            return true;

        }

        public void read()
        {
            if (id != "0")
            {
                string mima;
                string status;
                try
                {
                    //mima = vnp.ZSGW_KeyPass(vnp.RfidCardRequestAndReadNum());

                    //status = vnp.RfidCardRequestAndReadData("1", mima);
                    status = vnp.RfidCardRequestAndReadData("1", "FFFFFFFFFFFF");
                }
                catch (Exception)
                {

                    MessageBox.Show("此卡不是本公司的卡片！请与本公司联系。电话：010-51291008");
                    return;
                }

                if (status == "1")
                {
                    //MessageBox.Show("机器未插卡");
                }
                else
                    if (status == "0")
                    {
                        MessageBox.Show("端口未打卡");
                    }
                    else
                    {
                        //string data = "";
                        //byte blocknum = 1;
                        //VN.WriteData(blocknum, data);
                        //return;
                        //VN.ReadData(blocknum, ref data);
                        this.TxtCardId.Text = status;
                        id = this.TxtCardId.Text;
                    }




                memberInfo member = new memberInfo();
                Model.memberInfo memberMod = new Model.memberInfo();
                try
                {
                    //if (status != 0x02)
                    //{
                    
                    memberMod = member.GetModeCard(id);
                    if (memberMod == null)
                    {
                        memberMod = member.GetModels(memberId);
                    }
                    //}
                    //else
                    //{
                    //    memberMod = member.GetModelList("memberCardId='" + this.TxtCardId.Text + "'")[0];
                    //}

                }
                catch
                {
                    this.TxtCardId.Text = "";
                    //MessageBox.Show("找不到该会员");

                    return;
                }
                if (memberMod == null)
                {
                    if (this.TxtName.Text == "")
                    {
                        this.TxtConsume.Enabled = false;
                        //this.button1.Enabled = false;
                        //this.button2.Enabled = false;

                    }
                    else
                    {
                        this.TxtConsume.Enabled = true;
                        //this.button1.Enabled = true;
                        //this.button2.Enabled = true;
                    }
                    MessageBox.Show("未找到该会员");
                    return;

                }
                if (!test(memberMod))
                {
                    this.Close();
                    return;
                }


                TxtCardId.Text = memberMod.memberId;
                TxtName.Text = memberMod.memberName;
                TxtIntegral.Text = memberMod.point.ToString();
                TxtBalance.Text = memberMod.Balance.Value.ToString("F1");
                this.txtzhifuhoujifen.Text = memberMod.point.ToString();
                List<Model.goods> goodsList = getgood();
                //this.cboGoods.DataSource = goodSouse;
                cboGoods.Items.Add(goodsList);
                this.cboGoods.DisplayMember = "goodsName";
                this.cboGoods.ValueMember = "id";
                //this.cboGoods.AutoCompleteSource = AutoCompleteSource.ListItems;
                //if (this.TxtName.Text == "")
                //{
                //    this.TxtConsume.Enabled = false;
                //    this.button1.Enabled = false;
                //    this.button2.Enabled = false;

                //}
                //else
                //{
                //    this.TxtConsume.Enabled = true;
                //    this.button1.Enabled = true;
                //    this.button2.Enabled = true;
                //}
            }
            else if(memberId!="0")
            {
                memberInfo member = new memberInfo();
                Model.memberInfo memberMod = new Model.memberInfo();
                memberMod = member.GetModels(memberId);
                if (memberMod != null)
                {
                    if (!test(memberMod))
                    {
                        this.Close();
                        return;
                    }


                    TxtCardId.Text = memberMod.memberId;
                    TxtName.Text = memberMod.memberName;
                    TxtIntegral.Text = memberMod.point.ToString();
                    TxtBalance.Text = memberMod.Balance.Value.ToString("F1");
                    this.txtzhifuhoujifen.Text = memberMod.point.ToString();
                    List<Model.goods> goodsList = getgood();
                    //this.cboGoods.DataSource = goodSouse;
                    cboGoods.Items.Add(goodsList);
                    this.cboGoods.DisplayMember = "goodsName";
                    this.cboGoods.ValueMember = "id";
                }
                else
                {
                    if (this.TxtName.Text == "")
                    {
                        this.TxtConsume.Enabled = false;
                        //this.button1.Enabled = false;
                        //this.button2.Enabled = false;

                    }
                    else
                    {
                        this.TxtConsume.Enabled = true;
                        //this.button1.Enabled = true;
                        //this.button2.Enabled = true;
                    }
                    MessageBox.Show("未找到该会员");
                    return;
                }
            }

        }
        public int getStringLength(string str)
        {
            if (str.Equals(string.Empty))
                return 0;
            int strlen = 0;
            ASCIIEncoding strData = new ASCIIEncoding();
            //将字符串转换为ASCII编码的字节数字
            byte[] strBytes = strData.GetBytes(str);
            for (int i = 0; i <= strBytes.Length - 1; i++)
            {
                if (strBytes[i] == 63)  //中文都将编码为ASCII编码63,即"?"号
                    strlen++;
                strlen++;
            }
            return strlen;
        }

        public void CourseCbx()
        {
            ZG_member.BLL.CourseStage course = new ZG_member.BLL.CourseStage();
            ZG_member.Model.CourseStage courseMod = new ZG_member.Model.CourseStage();
            this.comboBox1.DataSource= course.GetListWhere("").Tables[0];
            this.comboBox1.ValueMember = "Id";
            this.comboBox1.DisplayMember = "StageName";
        }




        private void MemberSaleForm_Load(object sender, EventArgs e)
        {
            ZG_member.BLL.operatorInfo opera = new ZG_member.BLL.operatorInfo();
            ZG_member.Model.operatorInfo operaMode = new ZG_member.Model.operatorInfo();
            ZG_member.BLL.roleInfo role = new ZG_member.BLL.roleInfo();
            ZG_member.Model.roleInfo roleMode = new ZG_member.Model.roleInfo();
            operaMode = opera.GetModelList("username='" + MainForm.Operator + "'")[0];
            roleMode=role.GetModel(Convert.ToInt32(operaMode.roleId));
            if (roleMode.roleInfo1[38].ToString() == "1")
            {
                this.TxtDiscountAmount.ReadOnly = false;
            }
            else
            {
                this.TxtDiscountAmount.ReadOnly = true;
            }

            CourseCbx();
            this.Opacity = 0;
            this.timer1.Start();
            //this.tabPage2.Parent = null;

            read();
            this.TxtConsume.Focus();
            memberID = this.TxtCardId.Text;
            if (MainForm.xianshi == "1")
            {
                this.checkBox1.Checked = false;
            }
            //BLL.goodsType gt = new BLL.goodsType();
            //BLL.consumeSolution cs = new BLL.consumeSolution();

            BLL.goods goodbll = new BLL.goods();
            BLL.taocanjiluBLL tcbll = new taocanjiluBLL();
            ZG_member.BLL.memberInfo member = new ZG_member.BLL.memberInfo();
            ZG_member.Model.memberInfo memberMode = new ZG_member.Model.memberInfo();
            if (member.GetModeCard(id) == null)
            {
                return;
            }
                Model.taocanjilu tcmodle = tcbll.GetModelFormemberCardId(member.GetModeCard(id).memberId);
                ZG_member.BLL.Worker worker = new ZG_member.BLL.Worker();
                dataGridView4.DataSource = worker.GetListWhere("").Tables[0];

           



            this.dataGridView1.Rows.Clear();
            if (tcmodle == null)
            {
                return;
            }
            if (tcmodle.Xiangqing != null)
            {
                if (tcmodle.Xiangqing != "" && tcmodle.Xiangqing != null)
                {
                    string[] liebiao = tcmodle.Xiangqing.Split('|');
                    for (int i = 0; i < liebiao.Length; i++)
                    {
                        if (liebiao[i] == "")
                        {
                            return;
                        }
                        string[] liebiaoxiangqing = liebiao[i].Split(',');
                        Model.goods goodmodle = goodbll.getModelGoodsIdString(liebiaoxiangqing[0]);
                        if (goodmodle == null)
                        {
                            continue;
                        }
                        string[] jiazailiebiao = { liebiaoxiangqing[0], goodmodle.goodsName, liebiaoxiangqing[1], goodmodle.unit };
                        this.dataGridView1.Rows.Add(jiazailiebiao);
                    }
                }
            }
            bool sa = true;
            if (dataGridView1.Rows.Count != 0)
            {

                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    int vn = Convert.ToInt32(dataGridView1.Rows[i].Cells["goodcount"]);
                    if (vn != 0)
                    {
                        sa = false;
                    }
                }
            }
            if (sa == false)
            {
                MessageBox.Show("此会员套餐商品为空");
            }

        }
        goods g = new goods();
        public List<Model.goods> getgood()
        {

            string strwhere = "";
            return g.GetModelList(strwhere);
        }
        Model.taocanjilu tcmodle = new Model.taocanjilu();
        BLL.taocanjiluBLL tcbll = new taocanjiluBLL();
        BLL.taocanliushuiBLL tcluishui = new taocanliushuiBLL();
        /// <summary>
        /// 查找消费会员信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        string faxing = ConfigurationManager.AppSettings["faxin"];
        string temp = "";
        public string AdvPreProcess(string advContent)
        {
            string processContent = string.Empty;
            int count = 0;

            for (int i = 0; i < advContent.Length; i++)
            {
                processContent += advContent[i].ToString();

                if (advContent[i] == '\n')
                {
                    count = 0;
                    continue;
                }

                count++;

                if (advContent[i] < 0 || advContent[i] > 255)
                {
                    count++;
                }
               
                    if (count >= 14)
                    {
                        if (advContent.Length >= i + 2)
                        {
                            if (advContent[i + 1] != '\n')
                            {
                                processContent += "\n";
                                count = 0;
                            }
                        }
                    }
                
              

            }

            return processContent;
        }
        /// <summary>
        /// 消费完毕后更新数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAccount_Click(object sender, EventArgs e)
        {
            if (this.dataGridView2.Rows.Count != 0)
            {
                ZG_member.BLL.Leave leave = new ZG_member.BLL.Leave();
                DataTable dt= leave.GetListWhere(" memberId='" + this.TxtCardId.Text + "' and StartDate<='" + DateTime.Now.ToString("yyyy-MM-dd") + "' and EndDate>'" + DateTime.Now.ToString("yyyy-MM-dd") + "' ").Tables[0];
                if (dt.Rows.Count > 0)
                {
                    MessageBox.Show("请假期间不能上课");
                    return;
                }
            }

            textIsNull();
            if (cboGoods.Text != "" && Convert.ToInt32(this.numericUpDown1.Text) == 0)
            {
                MessageBox.Show("请输出数量");
            }
            if (TxtDiscountAmount.Text == "0")
            {
                TxtDiscountAmount.Text = "0";
            }
            //if (decimal.Parse(this.TxtConsume.Text) <= 0)
            //{
            //    this.TxtConsume.Text = "0";
            //}
            memberInfo memberfo = new memberInfo();

            Model.memberInfo memberInfoMod = new Model.memberInfo();

            try
            {
                //memberInfoMod = memberfo.GetModelList("memberId='" + this.TxtCardId.Text + "'")[0];
                memberInfoMod = memberfo.GetModels(this.TxtCardId.Text);
            }
            catch
            {

                return;
            }
            if (memberInfoMod.status == 2)
            {
                MessageBox.Show("您的卡片已停用！");
                return;
            }
            string passWord = "";
            if (this.TxtPwd.Text == "")
            {
                passWord = null;
            }
            else
            {
                passWord = this.TxtPwd.Text;

                MD5 md5 = new MD5CryptoServiceProvider();
                byte[] bt = Encoding.Default.GetBytes(passWord);
                bt = md5.ComputeHash(bt);
                passWord = BitConverter.ToString(bt).Replace("-", "");
            }


            if (passWord == memberInfoMod.pwd)
            {
                consumeSolution consBLL = new consumeSolution();
                ZG_member.Model.consumeSolution consModel = new ZG_member.Model.consumeSolution();
                string sss = this.TxtConsume.Text;




                if (decimal.Parse(this.TxtCrashPay.Text) > 0)
                {
                    DialogResult dr = MessageBox.Show("由于您卡上的余额不足，需要支付现金" + this.TxtCrashPay.Text + "元", "提示", MessageBoxButtons.YesNo);
                    if (dr == DialogResult.No)
                    {
                        return;
                    }
                    //else if (dr == DialogResult.No)
                    //{
                    //    int UpID = Convert.ToInt32(memberInfoMod.cardType);
                    //    ZG_member.Model.consumeSolution cModel = consBLL.GetModel(UpID);
                    //    if (cModel.Shezhangjinge != null)
                    //    {
                    //        if (decimal.Parse(this.TxtCrashPay.Text) > decimal.Parse(cModel.Shezhangjinge))
                    //        {
                    //            MessageBox.Show("赊账金额超出了最大金额！");
                    //            return;
                    //        }
                    //        memberInfoMod.Balance = 0 - decimal.Parse(this.TxtCrashPay.Text);
                    //    }
                    //    else
                    //    {
                    //        MessageBox.Show("您还没设置赊账金额！");
                    //        return;
                    //    }

                    //}

                }
                bool LeveUp = true;
                //if (Convert.ToDecimal(this.TxtConsume.Text) > 100000 && consBLL.GetModel(Convert.ToInt32(memberInfoMod.cardType)).nextLevelId != 0)
                //{                  
                //    int UpID = Convert.ToInt32(memberInfoMod.cardType);
                //    consModel = consBLL.GetModel(UpID);
                //    int nextUpID = Convert.ToInt32(consModel.nextLevelId);
                //    memberInfoMod.cardType = nextUpID;
                //    memberfo.Update(memberInfoMod);
                //    MessageBox.Show("恭喜您！单笔消费10万以上已升级为至尊会员！");
                //    LeveUp = false;
                //    //BLL.Duanxingneirong blldx = new Duanxingneirong();
                //    //Model.Duanxingneirong dxmodle = blldx.getmodel(3);
                //    //string fakaneirong = string.Format(dxmodle.Fasongneirong);
                //    //fakaneirong += "【国金黄金】";

                //    //try
                //    //{
                //    //    if (faxing == "1")
                //    //    {
                //    //        sf.sendMsg(dxmodle.Fasongneirong, memberInfoMod.Tel);
                //    //    }

                //    //}
                //    //catch (Exception)
                //    //{
                //    //    MessageBox.Show("由于计算机未连网，不能发信息！");

                //    //}


                //}
                //else
                //{

                //    string lastYear = DateTime.Now.AddYears(-1).ToString("yyyy-MM-dd");
                //    DataSet ds= memberfo.GetListSql("select memberCardId,SUM(consumeMoney)as Money from wasteBook where date>='"+lastYear+"' and date<='"+DateTime.Now.ToString("yyyy-MM-dd")+"' and memberCardId='"+TxtCardId.Text+"' group by memberCardId");
                //    if (ds.Tables[0].Rows.Count != 0)
                //    {
                //        string ss = ds.Tables[0].Rows.Count.ToString();
                //        if (Convert.ToInt32(ds.Tables[0].Rows[0]["Money"]) >= 100000 && consBLL.GetModel(Convert.ToInt32(memberInfoMod.cardType)).nextLevelId != 0)
                //        {
                //            int UpID = Convert.ToInt32(memberInfoMod.cardType);
                //            consModel = consBLL.GetModel(UpID);
                //            int nextUpID = Convert.ToInt32(consModel.nextLevelId);
                //            memberInfoMod.cardType = nextUpID;
                //            memberfo.Update(memberInfoMod);
                //            MessageBox.Show("恭喜您！一年内满10万,已自动升级为至尊会员");
                //            LeveUp = false;
                //            //BLL.Duanxingneirong blldx = new Duanxingneirong();
                //            //Model.Duanxingneirong dxmodle = blldx.getmodel(3);
                //            //string fakaneirong = string.Format(dxmodle.Fasongneirong);
                //            //fakaneirong += "【国金黄金】";
                //            //try
                //            //{
                //            //    if (faxing == "1")
                //            //    {
                //            //        sf.sendMsg(dxmodle.Fasongneirong, memberInfoMod.Tel);
                //            //    }

                //            //}
                //            //catch (Exception)
                //            //{
                //            //    MessageBox.Show("由于计算机未连网，不能发信息！");

                //            //}
                //        }
                //    }

                //}
                if (LeveUp == true)
                {
                    Model.consumeSolution cmdl = new Model.consumeSolution();

                    cmdl = cs.GetModel(Convert.ToInt32(memberInfoMod.cardType));

                    List<Model.consumeSolution> listcs = cs.GetModelList("");

                    for (int i = listcs.Count; i >= 1; i--)
                    {
                        if (cmdl.nextLevelId != 0)
                        {
                            if (listcs[i - 1].nextLevelId == 0)
                            {
                                continue;
                            }
                            if ((memberInfoMod.consume + decimal.Parse(this.TxtConsume.Text)) >= listcs[i - 1].levelUp)
                            {
                                memberInfoMod.cardType = listcs[i - 1].nextLevelId;
                                cmdl = cs.GetModel((int)memberInfoMod.cardType);
                                MessageBox.Show("恭喜您！您的会员卡升级升级为" + cmdl.solutionName + "！");
                                //BLL.Duanxingneirong blldx = new Duanxingneirong();
                                //Model.Duanxingneirong dxmodle = blldx.getmodel(3);
                                //string fakaneirong = string.Format(dxmodle.Fasongneirong);
                                //fakaneirong += "【国金黄金】";
                                //try
                                //{
                                //    if (faxing == "1")
                                //    {
                                //        sf.sendMsg(dxmodle.Fasongneirong, memberInfoMod.Tel);
                                //    }

                                //}
                                //catch (Exception)
                                //{
                                //    MessageBox.Show("由于计算机未连网，不能发信息！");

                                //}   
                            }

                        }
                        else
                        {

                        }

                    }
                }
                //if ((memberInfoMod.consume + decimal.Parse(this.TxtConsume.Text)) >= cmdl.levelUp)
                //{
                //    memberInfoMod.cardType = cmdl.nextLevelId;
                //    MainForm.cardtype = cmdl.nextLevelId.ToString();
                //    MessageBox.Show("恭喜您！您的会员卡升级了！");
                //    cmdl = cs.GetModel(memberInfoMod.cardType);
                //    mainForm.LblMemberType1.Text = cmdl.solutionName;

                //}

                //else
                //{

                //}
                if (Integral == "")
                {
                    Integral = "0";
                }

                goods goodsBLL = new goods();
                Model.goods goodsMode = new Model.goods();
                decimal duihuanqian = 0;
                for (int o = 0; o < dataGridView2.Rows.Count; o++)
                {
                    goodsMode = goodsBLL.getModelGoodsIdString(dataGridView2.Rows[o].Cells["goodid"].Value.ToString());
                    duihuanqian += Convert.ToInt32(dataGridView2.Rows[o].Cells["goodscount"].Value) * Convert.ToDecimal(goodsMode.price);
                }



                //memberInfoMod.Balance = memberInfoMod.Balance - decimal.Parse(TxtCardPay.Text) - duihuanqian;
                Model.consumeSolution cmdls = new Model.consumeSolution();

                cmdls = cs.GetModel(Convert.ToInt32(memberInfoMod.cardType));

                if (cmdls.solutionName != "销售")
                {
                    memberInfoMod.Balance = memberInfoMod.Balance - decimal.Parse(TxtCardPay.Text);
                }
                else
                {
                    memberInfoMod.Balance = memberInfoMod.Balance;
                }
                memberInfoMod.point = int.Parse(this.txtzhifuhoujifen.Text);
                memberInfoMod.consume = memberInfoMod.consume + decimal.Parse(this.TxtConsume.Text);

                memberfo.Update(memberInfoMod);
                //mainForm.LblBalance1.Text = (decimal.Parse(this.TxtBalance.Text) - decimal.Parse(TxtCardPay.Text)).ToString();
                //mainForm.LblIntegral1.Text = (decimal.Parse(this.TxtIntegral.Text) + decimal.Parse(Integral)).ToString();
                wasteBook wastebook = new wasteBook();
                Model.wasteBook wastebookModel = new Model.wasteBook();
                if (Convert.ToDouble(this.TxtDiscountAmount.Text) != Changeprice)
                {
                    wastebookModel.ChangepricePeople = MainForm.Operator;
                }
                if (button3.Text == "关闭")
                {
                    wastebookModel.Discount = Convert.ToSingle(this.numericUpDown2.Value) * 10;
                }
                else
                {
                    ZG_member.Model.memberInfo memModel = new ZG_member.Model.memberInfo();
                    memModel = memberfo.GetModels(this.TxtCardId.Text);
                    consumeSolution cons = new consumeSolution();
                    ZG_member.Model.consumeSolution consMode = new ZG_member.Model.consumeSolution();
                    consMode = cons.GetModel(Convert.ToInt32(memModel.cardType));
                    string memberDis = consMode.discountSolution;
                }
                if (this.dataGridView2.Rows.Count > 0)
                {
                    tcmodle.Memberid = this.TxtCardId.Text.Trim();

                    for (int i = 0; i < dataGridView1.Rows.Count; i++)
                    {
                        tcmodle.Xiangqing += dataGridView1.Rows[i].Cells["goodsid"].Value.ToString() + "," + dataGridView1.Rows[i].Cells["goodcount"].Value.ToString() + "|";
                    }
                    for (int i = 0; i < dataGridView2.Rows.Count; i++)
                    {
                        Model.taocanliushui tcliushuimodle = new Model.taocanliushui();
                        tcliushuimodle.Memberid = this.TxtCardId.Text;
                        tcliushuimodle.Goodid = dataGridView2.Rows[i].Cells["goodid"].Value.ToString();
                        tcliushuimodle.Goodcount = dataGridView2.Rows[i].Cells["goodscount"].Value.ToString();
                        tcliushuimodle.Time = dataGridView2.Rows[i].Cells["shijian"].Value.ToString(); ;
                        tcluishui.Add(tcliushuimodle);
                    }
                    tcbll.updatexiangqing(tcmodle);

                }


                #region 将消费金额添加到销售人下
                if (this.TxtDiscountAmount.Text != "0")
                {
                    ZG_member.BLL.SalesStaffList sale = new ZG_member.BLL.SalesStaffList();
                    ZG_member.Model.SalesStaffList saleMode = new ZG_member.Model.SalesStaffList();
                    string saleID = memberInfoMod.OpenTeacher;
                    saleMode = sale.GetModel(saleID);
                    saleMode.Money = saleMode.Money + tichengMoney;
                    //if (this.TxtConsume.Text.Substring(0, 1) != "-")
                    //{
                    //    saleMode.Money = saleMode.Money + Convert.ToDouble(this.TxtCrashPay.Text);
                    //}
                    //else
                    //{
                    //    saleMode.Money = saleMode.Money + Convert.ToDouble(this.TxtDiscountAmount.Text);
                    //}
                    sale.Update(saleMode);
                    ZG_member.BLL.SalesWasteBook saleWaste = new ZG_member.BLL.SalesWasteBook();
                    ZG_member.Model.SalesWasteBook saleWasteMode = new ZG_member.Model.SalesWasteBook();
                    saleWasteMode.SalesPersonId = saleMode.SalesPersonId;
                    saleWasteMode.Dates = DateTime.Now;
                    if (this.TxtDiscountAmount.Text.Substring(0,1) !="-")
                    {
                        saleWasteMode.Source = "消费";
                    }
                    else
                    {
                        saleWasteMode.Source = "退款";
                    }
                    saleWasteMode.money = Convert.ToDouble(this.TxtCrashPay.Text);
                    saleWasteMode.memberId = memberInfoMod.memberId;
                    saleWaste.add(saleWasteMode);
                }
                #endregion


                //存入数据
                wastebookModel.memberCardId = TxtCardId.Text;
                wastebookModel.consumeTimes = wastebookModel.consumeTimes + 1;
                wastebookModel.operatorId = MainForm.Operator;
                wastebookModel.consumeType = memberInfoMod.cardType;
                wastebookModel.cardPayMoney = decimal.Parse(TxtCardPay.Text);
                wastebookModel.cashPayMoney = decimal.Parse(TxtCrashPay.Text);
                wastebookModel.consumeMoney = decimal.Parse(TxtDiscountAmount.Text);
                wastebookModel.consumeIntegral = int.Parse(this.txtjifenzhifu.Text);
                //wastebookModel.totalIntegral = int.Parse(this.txtjifenzhifu.Text) + (int)decimal.Parse(Integral);
                wastebookModel.totalIntegral = int.Parse(this.txtzhifuhoujifen.Text);
                wastebookModel.exchangeIntegral = (int)decimal.Parse(Integral);
                wastebookModel.savingMoney =Convert.ToDecimal(this.TxtCrashPay.Text);
                wastebookModel.refundmentIntegral = 0;
                if (Convert.ToDouble(this.TxtDiscountAmount.Text) >= 0)
                {
                    wastebookModel.refundmentMoney = 0;
                }
                else
                {
                    wastebookModel.refundmentMoney = Convert.ToDecimal(this.TxtDiscountAmount.Text);
                }
                //wastebookModel.cardBalance = decimal.Parse(this.TxtBalance.Text) + decimal.Parse(TxtCardPay.Text);
                wastebookModel.cardBalance = memberInfoMod.Balance;
                wastebookModel.date = DateTime.Parse(DateTime.Now.ToString());
                wastebookModel.details = this.TxtOthers.Text;
                wastebookModel.terminalId = "0";
                wastebookModel.Discount =Convert.ToInt32(getzhekoulv());
                wastebookModel.Jiedairen = this.txtjiedairen.Text;
                wastebookModel.Voucher = this.txtVoucher.Text;
                wastebookModel.VoucherMoney = Convert.ToDouble(this.txtVoucherMoney.Text);
                wastebook.Add(wastebookModel);




                #region 将钱算入施工下
                if (dataGridView4.Rows.Count!=0||dataGridView3.Rows.Count != 0)
                {
                    ZG_member.BLL.Worker worker = new ZG_member.BLL.Worker();
                    ZG_member.BLL.WorkerWasteBook workerBook = new ZG_member.BLL.WorkerWasteBook();
                    ZG_member.Model.WorkerWasteBook workerBookMode = new ZG_member.Model.WorkerWasteBook();
                    ZG_member.BLL.goods goods=new ZG_member.BLL.goods();
                    ZG_member.Model.goods gdMode=new ZG_member.Model.goods();
                    double money = Convert.ToDouble(this.TxtDiscountAmount.Text);
                    List<string> workerID = new List<string>();
                    decimal taocanMoney=0;
                    decimal shugongqian=0;
                    for (int i = 0; i < dataGridView4.Rows.Count; i++)
                    {
                        string mb = "";
                        if (dataGridView4.Rows[i].Cells["cbxWorker"].Value != null)
                        {
                            mb = dataGridView4.Rows[i].Cells["cbxWorker"].Value.ToString();
                        }
                        else
                        {
                            mb = "false";
                        }
                        if (mb == "true")
                        {
                            workerID.Add(dataGridView4.Rows[i].Cells["Ids"].Value.ToString());
                        }
                    }
                    if(dataGridView2.Rows.Count!=0)
                    {
                        for (int i = 0; i < dataGridView2.Rows.Count; i++)
			            {
			                gdMode=goods.getModelGoodsIdString(dataGridView2.Rows[i].Cells["goodid"].Value.ToString());
                            taocanMoney+= Convert.ToInt32(dataGridView2.Rows[i].Cells["goodscount"].Value)* Convert.ToDecimal(gdMode.price);

			            }
                        if (workerID.Count == 0)
                        {
                            shugongqian = taocanMoney;
                        }
                        else
                        {
                            shugongqian = taocanMoney / workerID.Count;
                        }
                    }


               
                    double workerMoney = money / workerID.Count;
                    for (int i = 0; i < workerID.Count; i++)
                    {
                        ZG_member.Model.Worker workerMode = new ZG_member.Model.Worker();
                         workerMode=  worker.GetModel(Convert.ToInt32(workerID[i]));
                         workerMode.Money = workerMode.Money + workerMoney + Convert.ToDouble(Math.Round(shugongqian, 2));
                         worker.Update(workerMode);
                         workerBookMode.WorkerId = worker.GetModel(Convert.ToInt32(workerID[i])).WorkerId;
                         workerBookMode.Dates =Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
                         workerBookMode.money = Convert.ToDouble(Math.Round(shugongqian, 2)) + workerMoney;
                         workerBookMode.memberId = this.TxtCardId.Text;
                         workerBook.add(workerBookMode);
                    }
                }
                #endregion
                


                if (this.CbxPrintInfo.Checked == true)
                {

                    printPreviewDialog1.Document = this.printDocument1;
                    this.printDocument1.PrintController = new System.Drawing.Printing.StandardPrintController();
                    printPreviewDialog1.Document.Print();

                    DialogResult dr = MessageBox.Show("是否再次打印？", "提示", MessageBoxButtons.YesNo);
                    while (dr == DialogResult.Yes)
                    {
                        dayincishu++;
                        printPreviewDialog1.Document = this.printDocument1;
                        this.printDocument1.PrintController = new System.Drawing.Printing.StandardPrintController();
                        printPreviewDialog1.Document.Print();
                        dr = DialogResult.No;
                    }

                }
                //if (checkBox1.Checked)
                //{
                //    ZG_member.SendMsgsForm sm = new ZG_member.SendMsgsForm();
                //    BLL.SMS sms = new SMS();
                //    Model.SMS smsmodle = sms.GetListmodel();
                //    string weihao = this.TxtCardId.Text.Substring(11);
                //    string xiaofeineirong = string.Format(smsmodle.SMSneirong1, weihao, decimal.Parse(Integral).ToString("0"), smsmodle.SMSjifen1);
                //    xiaofeineirong += "【国金黄金】";
                //    sm.sendMsg(xiaofeineirong, memberInfoMod.Tel);
                //    memberfo.shifoushouxinUpdate("0",TxtCardId.Text);

                //}
                goodsInfo goodsinfo = new goodsInfo();
                goods gd = new goods();
                if (dataGridView3.RowCount == 0)
                {

                }
                else
                {
                    Model.goodsInfo goodsmodl = new Model.goodsInfo();

                    for (int i = 0; i < dataGridView3.RowCount; i++)
                    {
                        goodsmodl.Gid = g.GetId(dataGridView3.Rows[i].Cells["gdsname"].Value.ToString());
                        if (dataGridView3.Rows[i].Cells["price"].Value.ToString() == "-")
                        {
                            goodsmodl.Goodsprice = decimal.Parse(dataGridView3.Rows[i].Cells["Promotionprice"].Value.ToString());
                        }
                        else
                        {
                            //goodsmodl.Goodsprice = decimal.Parse(dataGridView3.Rows[i].Cells["price"].Value.ToString());
                            goodsmodl.Goodsprice = decimal.Parse(dataGridView3.Rows[i].Cells["Promotionprice"].Value.ToString());
                        }

                        goodsmodl.Goodscount = int.Parse(dataGridView3.Rows[i].Cells["count"].Value.ToString());
                        goodsmodl.Selltime = DateTime.Now.ToString();
                        goodsmodl.Zhekou = dataGridView3.Rows[i].Cells["折扣率"].Value.ToString();
                        //goodsmodl.wasteBookId = goodsinfo.GetwasteBookMaxId()
                        goodsmodl.wasteBookId = goodsinfo.GetMaxwasteBookId();
                        goodsinfo.add(goodsmodl);

                        Model.goods goods = gd.GetModel(g.GetbyId(dataGridView3.Rows[i].Cells["gdsname"].Value.ToString()));
                        goods.amount = goods.amount - int.Parse(dataGridView3.Rows[i].Cells["count"].Value.ToString());
                        gd.Update(goods);

                    }
                }
                #region 打印

                if (id != "0")
                {
                    string mima = vnp.ZSGW_KeyPass(vnp.RfidCardRequestAndReadNum());
                    //mima = "FFFFFFFFFFFF";
                    string status = vnp.RfidCardRequestAndReadData("1", mima);
                    if (status == "0" || status == "1")
                    {

                    }
                    else
                    {
                        id = this.TxtCardId.Text;
                        Model.memberInfo mode = GetModel();
                        int Nowday = DateTime.Now.Day;
                        int Nowyue = DateTime.Now.Month;

                        int shengriday = ((DateTime)mode.birthDay).Day;
                        int shengriyue = ((DateTime)mode.birthDay).Month;
                        IntegrationExchangeForm i = new IntegrationExchangeForm(mainfrom, this.TxtCardId.Text, vnp);
                        //i.keyongjifen(mode.memberId, (int)mode.cardType);
                        int keyong = (int)mode.point - int.Parse(i.keyongjifen(mode.memberId, (int)mode.cardType));
                        consumeSolution ct = new consumeSolution();
                        Model.consumeSolution css = ct.GetModel(Convert.ToInt32(mode.cardType));
                        string sex = (bool)mode.sex ? "男" : "女";
                        string sssw = (decimal.Parse(this.TxtConsume.Text) - decimal.Parse(this.TxtDiscountAmount.Text)).ToString("F1");                                //会员卡号#卡片类型#会员姓名#性　　别#卡片状态#办卡日期#截止日期#累计积分                                                 #本次积分#可用积分                                                                  #本次消费                      #储值余额#折扣金额#本次充值#积分支付#现金消费#空　　行
                        string[] ModelArray = new string[] { mode.memberId, css.solutionName, mode.memberName, sex, "正常", Convert.ToDateTime(mode.createDate).ToString("yyyy-MM-dd"), Convert.ToDateTime(mode.expiresDate).ToString("yyyy-MM-dd"), mode.point.ToString(), ((int)decimal.Parse(Integral)).ToString(), keyong.ToString(), this.TxtDiscountAmount.Text, ((decimal)mode.Balance).ToString("F1"), (decimal.Parse(this.TxtConsume.Text) - decimal.Parse(this.TxtDiscountAmount.Text)).ToString("F1"), "0", "0", this.TxtCrashPay.Text, "" };
                        string Go = print(ModelArray);
                        Go = "\n" + Go;
                        birthdayremind br = new birthdayremind();
                        Model.birthdayremind brmodl = br.GetModel(2);
                        int aa = br.tixingday(this.TxtCardId.Text);
                        if (aa < brmodl.Remindday && aa != 0 && aa > 0)
                        {
                            if (Nowyue == shengriyue)
                            {
                                if (Nowday < shengriday)
                                {
                                    string one = brmodl.Remindcontent.Replace("{now}", DateTime.Now.ToString("yyyy-MM-dd"));
                                    string two = one.Replace("{leftDays}", aa.ToString());
                                    Go += two + "\n";
                                }
                            }
                            if (Nowyue < shengriyue)
                            {
                                string one = brmodl.Remindcontent.Replace("{now}", DateTime.Now.ToString("yyyy-MM-dd"));
                                string two = one.Replace("{leftDays}", aa.ToString());
                                Go += two + "\n";
                            }

                        }
                        else if (aa == 0)
                        {
                            Go += AdvPreProcess(brmodl.Nowremindcontent1) + "\n";
                        }
                        if (dataGridView2.Rows.Count > 0)
                        {
                            Go += "项目名           使用量\n";

                            for (int w = 0; w < dataGridView2.Rows.Count; w++)
                            {
                                string goodsname = AdvPreProcess(dataGridView2.Rows[w].Cells["goodsname"].Value.ToString());
                                Go += goodsname;
                                int temp = 0;
                                if (goodsname.LastIndexOf("\n") == -1)
                                {
                                    temp = goodsname.Length;
                                }
                                else
                                {
                                    temp = getStringLength(goodsname.Substring(goodsname.LastIndexOf("\n")));
                                }
                                for (int q = 0; q < 19 - temp; q++)
                                {
                                    Go += " ";
                                }
                                string duihuanshu = dataGridView2.Rows[w].Cells["goodscount"].Value.ToString();
                                //string zongshu = "";
                                //string duihuanID = dataGridView2.Rows[w].Cells["goodid"].Value.ToString();
                                //for (int r = 0; r < dataGridView1.Rows.Count; r++)
                                //{
                                //    if (dataGridView1.Rows[r].Cells["goodsid"].Value.ToString() == duihuanID)
                                //    {
                                //        zongshu = dataGridView1.Rows[r].Cells["goodcount"].Value.ToString();
                                //    }
                                //}
                                //Go += Convert.ToInt32(zongshu) - Convert.ToInt32(duihuanshu) + "\n";
                                Go += Convert.ToInt32(duihuanshu) + "\n";
                                //zongshu = "";
                            }
                        }
                        Go += AdvPreProcess(this.textBox1.Text);

                        vnp.PrintBufferClear();
                        vnp.PrintCharacterDataSetting(Go);
                        vnp.ErasePrintDischarge3();
                    }

                }

                #endregion
                MessageBox.Show("交易成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                mainfrom.shifouxianshi(MainForm.Operator);

                this.Close();
                //mainForm.shifouxianshi(MainForm.Operator);
            }
            else
            {
                MessageBox.Show("密码不正确!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

        }
        ZG_member.SendMsgsForm sf = new ZG_member.SendMsgsForm();
        string cardname = "";
        //update dbo.billTemplates set templates = '会员卡号: {0}  会员姓名: {1}  当前积分: {2}  当前余额: {3}  本次消费: {4}  卡片支付: {5}  折扣后金额: {6}  现金支付: {7}  消费详情: {8}  附加信息: {9}  '+CHAR(10) where id = 1
        public string gettemplates(int id)
        {
            Model.cardTemplates btmodel = new Model.cardTemplates();
            cardTemplates bt = new cardTemplates();
            btmodel = bt.GetModel(id);
            return btmodel.template;
        }
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            consumeSolution ct = new consumeSolution();

            Model.memberInfo mode = GetModel();
            Model.consumeSolution css = ct.GetModel(Convert.ToInt32(mode.cardType));
            string xiaopiaoprint = gettemplates((int)css.cardTemplateId);
            IntegrationExchangeForm integ = new IntegrationExchangeForm(mainfrom, this.TxtCardId.Text, vnp);
            integ.keyongjifen(mode.memberId, (int)mode.cardType);
            int keyong = (int)mode.point - int.Parse(integ.keyongjifen(mode.memberId, (int)mode.cardType));
            string sex = (bool)mode.sex ? "男" : "女";


            string insertString = "";

            if (this.dataGridView2.Rows.Count > 0)
            {
                string[] ModelArray = new string[] { mode.memberId, css.solutionName, mode.memberName, sex, "正常", mode.createDate.ToString(), mode.expiresDate.ToString(), mode.point.ToString(), ((int)decimal.Parse(Integral)).ToString(), keyong.ToString(), this.TxtDiscountAmount.Text, ((decimal)mode.Balance).ToString("F1"), "0", "0", txtjifenzhifu.Text, this.TxtCrashPay.Text };
                goods good = new goods();
                ZG_member.Model.goods goodsMode = new ZG_member.Model.goods();
                xiaopiaoprint = print(ModelArray);
                //int sa = xiaopiaoprint.IndexOf("附加信息");
                insertString += "名称\t     数量   单价   金额\n";
                for (int i = 0; i < dataGridView2.Rows.Count; i++)
                {
                    insertString += i + 1 + ".";
                    string goodsId = dataGridView2.Rows[i].Cells["goodid"].Value.ToString();
                    goodsMode = good.getModelGoodsIdString(goodsId);
                    string goodscount = dataGridView2.Rows[i].Cells["goodscount"].Value.ToString();
                    string gdName = goodsMode.goodsName;
                    List<string> list = new List<string>();
                    if (gdName.Length > 5)
                    {
                        decimal num = Convert.ToDecimal(gdName.Length) / 5;
                        int s = Convert.ToInt32(Math.Abs(num));
                        if (num > s)
                        {
                            s += 1;
                        }
                        int startNum = -5;
                        for (int v = 0; v < s; v++)
                        {
                            startNum += 5;
                            if (v == s - 1)
                            {
                                list.Add(gdName.Substring(startNum));
                            }
                            else
                            {
                                list.Add(gdName.Substring(startNum, 5));
                            }
                        }
                    }
                    else
                    {
                        list.Add(gdName);
                    }

                    for (int o = 0; o < list.Count; o++)
                    {

                        if (o > 0)
                        {
                            insertString += list[o].ToString() + "\n";
                            continue;
                        }
                        decimal sl = Convert.ToDecimal(goodscount) * Convert.ToDecimal(goodsMode.price);
                        insertString += "" + list[0].ToString() + "  " + goodscount + "  " + goodsMode.price + " " + sl + "\n";
                    }
                }
                xiaopiaoprint += insertString;

            }
            if (this.dataGridView3.Rows.Count > 0)
            {
                string[] ModelArray = new string[] { mode.memberId, css.solutionName, mode.memberName, sex, "正常", mode.createDate.ToString(), mode.expiresDate.ToString(), mode.point.ToString(), ((int)decimal.Parse(Integral)).ToString(), keyong.ToString(), this.TxtDiscountAmount.Text, ((decimal)mode.Balance).ToString("F1"), "0", "0", txtjifenzhifu.Text, this.TxtCrashPay.Text };
                goods good = new goods();
                ZG_member.Model.goods goodsMode = new ZG_member.Model.goods();
                xiaopiaoprint = print(ModelArray);
                //int sa = xiaopiaoprint.IndexOf("附加信息");
                insertString += "名称\t     数量   单价   金额\n";
                for (int i = 0; i < dataGridView3.Rows.Count; i++)
                {
                    insertString += i + 1 + ".";
                    //string goodsId=dataGridView3.Rows[i].Cells["goodid"].Value.ToString();
                    //goodsMode = good.getModelGoodsIdString(goodsId);
                    string goodscount = dataGridView3.Rows[i].Cells["count"].Value.ToString();
                    string gdName = dataGridView3.Rows[i].Cells["gdsname"].Value.ToString();

                    List<string> list = new List<string>();
                    if (gdName.Length > 5)
                    {
                        decimal num = Convert.ToDecimal(gdName.Length) / 5;
                        int s = Convert.ToInt32(Math.Abs(num));
                        if (num > s)
                        {
                            s += 1;
                        }
                        int startNum = -5;
                        for (int v = 0; v < s; v++)
                        {
                            startNum += 5;
                            if (v == s - 1)
                            {
                                list.Add(gdName.Substring(startNum));
                            }
                            else
                            {
                                list.Add(gdName.Substring(startNum, 5));
                            }
                        }
                    }
                    else
                    {
                        list.Add(gdName);
                    }

                    for (int o = 0; o < list.Count; o++)
                    {

                        if (o > 0)
                        {
                            insertString += list[o].ToString() + "\n";
                            continue;
                        }
                        decimal sl = Convert.ToDecimal(goodscount) * Convert.ToDecimal(dataGridView3.Rows[i].Cells["price"].Value.ToString());
                        insertString += "" + list[0].ToString() + "  " + goodscount + "  " + dataGridView3.Rows[i].Cells["price"].Value.ToString() + " " + sl + "\n";
                    }
                }
                xiaopiaoprint += insertString;
            }
            if (this.dataGridView3.Rows.Count <= 0 && this.dataGridView2.Rows.Count <= 0)
            {
                if (this.TxtConsume.Text == "0")
                {
                    return;
                }
                string[] ModelArray = new string[] { mode.memberId, css.solutionName, mode.memberName, sex, "正常", mode.createDate.ToString(), mode.expiresDate.ToString(), mode.point.ToString(), ((int)decimal.Parse(Integral)).ToString(), keyong.ToString(), this.TxtDiscountAmount.Text, ((decimal)mode.Balance).ToString("F1"), "0", "0", txtjifenzhifu.Text, this.TxtCrashPay.Text };
                //xiaopiaoprint = string.Format(xiaopiaoprint, this.TxtCardId.Text, this.TxtName.Text, this.TxtIntegral.Text, this.TxtBalance.Text, this.TxtConsume.Text, this.TxtCardPay.Text, this.TxtDiscountAmount.Text, this.TxtCrashPay.Text, this.TxtOthers.Text);

                xiaopiaoprint = print(ModelArray);
            }
            xiaopiaoprint += "\n操作员：" + MainForm.Operator + "|接待人：" + txtjiedairen.Text;
            if (dayincishu == 1)
            {
                xiaopiaoprint += "\n\t\t     客户联";
            }
            if (dayincishu == 2)
            {
                xiaopiaoprint += "\n\t\t     存根联";
            }
            e.Graphics.DrawString(xiaopiaoprint, new Font("黑体", 9, FontStyle.Regular), Brushes.Black, 10, 10);
        }
        public string print(string[] ModelArray)
        {
            cardTemplates ct = new cardTemplates();
            memberInfo m = new memberInfo();
            
            Model.memberInfo mo = m.GetModels(memberId);

            Card((int)mo.cardType);
            Model.memberInfo mode = GetModel();
            temp = temp.Replace("\n", "#");
            string[] users = temp.Split('#');
            string muban = "会员卡号#卡片类型#会员姓名#性　　别#卡片状态#办卡日期#截止日期#累计积分#本次积分#可用积分#本次消费#储值余额#折扣金额#本次充值#积分支付#现金消费#空　　行";

            string[] mubanArray = muban.Split('#');

            string[] ModelArray1 = ModelArray;
            string a = users.Length.ToString();

            string t = "";

            for (int i = 0; i < users.Length; i++)
            {
                t += users[i];
                for (int j = 0; j < mubanArray.Length - 1; j++)
                {
                    if (users[i] == mubanArray[j])
                    {
                        t += ":" + ModelArray[j];

                    }

                }
                t += "\n";
            }

            string content = t.Replace("空　　行", "");
            return content;

        }
        public void Card(int id)
        {
            ZG_member.BLL.consumeSolution cm = new ZG_member.BLL.consumeSolution();
            ZG_member.BLL.cardTemplates carTemp = new ZG_member.BLL.cardTemplates();
            var consu = cm.GetModel(id);
            cardname = consu.solutionName;
            var cardID = consu.cardTemplateId;
            var card = carTemp.GetModel(Convert.ToInt32(cardID));
            temp = card.template;
        }
        public ZG_member.Model.memberInfo GetModel()
        {
            memberInfo m = new memberInfo();
             ZG_member.Model.memberInfo mem;
            if (id != "0")
            {
                mem = m.GetModeCard(id);
            }
            else
            {
                 mem = m.GetModels(memberId);
            }
            return mem;
        }



        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void TxtCardPay_TextChanged(object sender, EventArgs e)
        {
            //textIsNull();
            //TxtConsume.Text = (decimal.Parse(TxtCrashPay.Text) + decimal.Parse(TxtCardPay.Text)).ToString();
        }

        private void textIsNull()
        {
            if (string.IsNullOrEmpty(TxtCardPay.Text))
            {
                TxtCardPay.Text = "0";
            }
            if (string.IsNullOrEmpty(TxtCrashPay.Text))
            {
                TxtCrashPay.Text = "0";
            }
        }

        private void TxtCrashPay_TextChanged(object sender, EventArgs e)
        {
            //textIsNull();
            //TxtConsume.Text = (decimal.Parse(TxtCrashPay.Text) + decimal.Parse(TxtCardPay.Text)).ToString();
        }

        private void TxtCardPay_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)13 && e.KeyChar != (char)8)
            {
                e.Handled = true;
            }
        }

        private void TxtCrashPay_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)13 && e.KeyChar != (char)8)
            {
                e.Handled = true;
            }
        }
        string[] addname = new string[100];
        decimal[] addprice = new decimal[100];
        decimal[] addcuxiaoprice = new decimal[100];
        bool[] addshifoucuxiao = new bool[100];

        decimal[] addcount = new decimal[100];
        bool[] addteshuzhekou = new bool[100];
        string[] addzhekoulv = new string[100];
        string[] addzongjine = new string[100];


        //public string getzhekoulv()
        //{
        //    Model.consumeSolution cm = new Model.consumeSolution();
        //    memberInfo m = new memberInfo();
        //    Model.memberInfo mi = m.GetUserIdMode(this.TxtCardId.Text);
        //    int idd = (int)mi.cardType;
        //    goods g = new goods();
        //    string discountSolution = "";
        //    //Model.goods gm = g.GetModelList(" goodsname = '" + dataGridView1.Rows[j].Cells["count"].Value.ToString() + "'")[0];
        //    cm = cs.GetModel((int)mi.cardType);
        //    //string discountSolution = cm.discountSolution;
        //    Model.goods gm = g.GetModelList(" goodsname = '" + this.cboGoods.Text + "'")[0];
        //    discountSolution = cm.discountSolution;

        //    if (bool.Parse(gm.Promotion1))
        //    {
        //        if (cm.solutionName != "金卡")
        //        {
        //            discountSolution = gm.lowestOff;
        //            return discountSolution;
        //        }
        //        else
        //        {
        //            discountSolution = "100";
        //            return discountSolution;
        //        }

        //    }




        //        //cm = cs.GetModel((int)mi.cardType);
        //        //string yaa = "白金卡";
        //        //string jaa = "金卡";

        //        //if (cm.solutionName.IndexOf(yaa) > -1)
        //        //{
        //        //    if (cm.discountSolution == "100")
        //        //    {
        //        //        discountSolution = gm.Silverdiscount;
        //        //    }
        //        //    else if (gm.Silverdiscount == "100")
        //        //    {
        //        //        discountSolution = cm.discountSolution;
        //        //    }
        //        //    else
        //        //    {
        //        //        string aaaa = (decimal.Parse(cm.discountSolution) * decimal.Parse(gm.Silverdiscount)).ToString("F1");
        //        //        discountSolution = aaaa.Substring(0, 2);
        //        //        if (!(int.Parse(discountSolution) > 10))
        //        //        {
        //        //            discountSolution = (decimal.Parse(discountSolution) * 10).ToString("F1");
        //        //        }
        //        //        else
        //        //        {

        //        //        }

        //        //    }


        //        //}
        //        //else if (cm.solutionName.IndexOf(jaa) > -1)
        //        //{
        //        //    if (cm.discountSolution == "100")
        //        //    {
        //        //        discountSolution = gm.Golddiscount;
        //        //    }
        //        //    else if (gm.Golddiscount == "100")
        //        //    {
        //        //        discountSolution = cm.discountSolution;
        //        //    }
        //        //    else
        //        //    {
        //        //        string aaaa = (decimal.Parse(cm.discountSolution) * decimal.Parse(gm.Golddiscount)).ToString("F1");
        //        //        discountSolution = aaaa.Substring(0, 2);
        //        //        if (!(int.Parse(discountSolution) > 10))
        //        //        {
        //        //            discountSolution = (decimal.Parse(discountSolution) * 10).ToString("F1");
        //        //        }
        //        //        else
        //        //        {

        //        //        }


        //        //    }


        //        // }



        //    //birthdayremind br = new birthdayremind();
        //    //Model.birthdayremind brmodl = br.GetModel(2);
        //    //int aa = br.tixingday(this.TxtCardId.Text);
        //    //string[] shengrijifen = brmodl.Birthdaydiscount.Split();
        //    //if (aa == 0)
        //    //{
        //    //    discountSolution = brmodl.Birthdaydiscount;
        //    //}
        //    return discountSolution;
        //}





        consumeSolution cs = new consumeSolution();
        public decimal buyzhekou(decimal price)
        {
            Model.consumeSolution cm = new Model.consumeSolution();
            memberInfo m = new memberInfo();
            Model.memberInfo mi = m.GetUserIdMode(this.TxtCardId.Text);
            int idd = (int)mi.cardType;
            goods g = new goods();
            string discountSolution = "";
            //Model.goods gm = g.GetModelList(" goodsname = '" + dataGridView1.Rows[j].Cells["count"].Value.ToString() + "'")[0];
            cm = cs.GetModel((int)mi.cardType);
            discountSolution = cm.discountSolution;
            //string discountSolution = cm.discountSolution;
            //if (dataGridView1.Rows.Count == 0)
            //{
            //    discountSolution = cm.discountSolution;
            //}
            //for (int i = 0; i < dataGridView1.Rows.Count; i++)
            //{
            //    if (dataGridView1.Rows.Count == 0)
            //    {
            //        discountSolution = cm.discountSolution;
            //        break;
            //    }
            //Model.goods gm = g.GetModelList(" goodsname = '" + dataGridView1.Rows[i].Cells["goodsname"].Value.ToString() + "'")[0];
            //cm = cs.GetModel((int)mi.cardType);
            //string yaa = "白金卡";
            //string jaa = "金卡";



            //if (cm.solutionName.IndexOf(yaa) > -1)
            //{
            //    if (cm.discountSolution == "100")
            //    {
            //        discountSolution = gm.Silverdiscount;
            //    }
            //    else if (gm.Silverdiscount == "100")
            //    {
            //        discountSolution = cm.discountSolution;
            //    }
            //    else
            //    {
            //        string aaaa = (decimal.Parse(cm.discountSolution) * decimal.Parse(gm.Silverdiscount)).ToString("F1");
            //        discountSolution = aaaa.Substring(0, 2);
            //        if (!(int.Parse(discountSolution) > 10))
            //        {
            //            discountSolution = (decimal.Parse(discountSolution) * 10).ToString("F1");
            //        }
            //        else
            //        {

            //        }

            //    }


            //}
            //else if (cm.solutionName.IndexOf(jaa) > -1)
            //{
            //    if (cm.discountSolution == "100")
            //    {
            //        discountSolution = gm.Golddiscount;
            //    }
            //    else if(gm.Golddiscount == "100")
            //    {
            //        discountSolution = cm.discountSolution;
            //    }
            //    else
            //    {
            //        string aaaa = (decimal.Parse(cm.discountSolution) * decimal.Parse(gm.Golddiscount)).ToString("F1");
            //        discountSolution = aaaa.Substring(0, 2);
            //        if (!(int.Parse(discountSolution)>10))
            //        {
            //            discountSolution = (decimal.Parse(discountSolution) * 10).ToString("F1");
            //        }
            //        else
            //        {

            //        }


            //    }
            //}

            //}



            //birthdayremind br = new birthdayremind();
            //Model.birthdayremind brmodl = br.GetModel(2);
            //int aa = br.tixingday(this.TxtCardId.Text);
            //if (aa == 0) {
            //    discountSolution = brmodl.Birthdaydiscount;
            //}
            decimal newprice = price * (decimal.Parse(discountSolution) / 100);
            return newprice;
        }

        public string buypart(decimal price)
        {
            Model.consumeSolution cm = new Model.consumeSolution();

            memberInfo mi = new memberInfo();
            Model.memberInfo memberInfoMod = mi.GetModels(this.TxtCardId.Text);
            cm = cs.GetModel((int)memberInfoMod.cardType);
            string consumeSolution = cm.consumeSolution1;
            string[] one = consumeSolution.Split('|');
            string part = "0";
            int yushu = 0;
            if (price == 0)
            {
                return part;
            }

            for (int i = 0; yushu == 0; i++)
            {

                string[] two = one[i].Split(',');


                if (two[0] == "")
                {

                    break;
                }
                else
                {
                    if (price >= int.Parse(two[0]))
                    {

                        decimal beishu = price / int.Parse(two[0]);

                        part = (beishu * int.Parse(two[1])).ToString("F0");
                    }
                }
            }

            //birthdayremind br = new birthdayremind();
            //Model.birthdayremind brmodl = br.GetModel(2);
            //int aa = br.tixingday(this.TxtCardId.Text);
            //string shengrijifen = brmodl.Birthdaydiscount;
            //if (aa == 0)
            //{

            //    //decimal beishu = price / int.Parse(shengrijifen[0]);

            //    part = (int.Parse(shengrijifen) * decimal.Parse(part)).ToString();
            //    return part;
            //}


            return part;
        }
        //public string xunhuan(int yushu, int i, decimal price, string part, string[] one)
        //{
        //    if (yushu == 0)
        //    {
        //        return part = yushu.ToString();
        //    }
        //    string[] two = one[i].Split(',');

        //    yushu = (int)(price % decimal.Parse(two[0]));
        //    int zhengshu = (int)price - yushu;

        //    int beishu = zhengshu / int.Parse(two[0]);
        //    part = (beishu * int.Parse(two[1])).ToString();
        //    if (yushu > 0)
        //    {

        //    }

        //}

        //private void button1_Click(object sender, EventArgs e)
        //{
        //    string zhekoulv = getzhekoulv();


        //    bool zhekou = false;

        //    if (this.button3.Text != "启用")
        //    {
        //        DialogResult dt = MessageBox.Show("请问您是否使用特殊折扣？", "温馨提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
        //        if (dt == DialogResult.Yes)
        //        {
        //            zhekou = true;
        //        }
        //    }



        //    if (this.cboGoods.Text == null)
        //    {
        //        MessageBox.Show("请选择商品！");
        //    }
        //    else if (this.numericUpDown1.Value == 0)
        //    {
        //        MessageBox.Show("请输入数量！");
        //    }
        //    else
        //    {
        //        Model.goods goodmd = g.GetModel(g.GetbyId(this.cboGoods.Text));
        //        if (goodmd.amount < this.numericUpDown1.Value)
        //        {
        //            MessageBox.Show("该商品数量不足！");
        //            return;
        //        }
        //        if (dataGridView1.RowCount > 0)
        //        {
        //            for (int i = 0; i < dataGridView1.Rows.Count; i++)
        //            {
        //                if (goodmd.goodsName == dataGridView1.Rows[i].Cells["goodsname"].Value.ToString())
        //                {
        //                    if (goodmd.amount < (int.Parse(dataGridView1.Rows[i].Cells["count"].Value.ToString()) + this.numericUpDown1.Value))
        //                    {
        //                        MessageBox.Show(dataGridView1.Rows[i].Cells["goodsname"].Value.ToString() + "该商品数量不足！");
        //                        return;
        //                    }
        //                }

        //            }

        //        }


        //        for (int i = 0; i < addname.Length; i++)
        //        {
        //            if (addname[i]==null)
        //            {
        //                Model.goods gm = new Model.goods();
        //                gm = g.GetModel(int.Parse(this.cboGoods.SelectedValue.ToString()));
        //                addname[i] = gm.goodsName;
        //                addprice[i] = (decimal)gm.price;
        //                addcuxiaoprice[i] = decimal.Parse(gm.Promotionprice1);
        //                addshifoucuxiao[i] = bool.Parse(gm.Promotion1);
        //                addcount[i] = this.numericUpDown1.Value;
        //                addteshuzhekou[i] = zhekou;
        //                if (this.button3.Text == "启用")
        //                {
        //                    addzhekoulv[i] = (decimal.Parse(zhekoulv)/10).ToString();
        //                    if (addshifoucuxiao[i]==true)
        //                    {
        //                        addzongjine[i] = (addcuxiaoprice[i] * addcount[i] * (decimal.Parse(zhekoulv) / 100)).ToString("F1");
        //                    }
        //                    else
        //                    {
        //                        addzongjine[i] = (addprice[i] * addcount[i] * (decimal.Parse(zhekoulv) / 100)).ToString("F1");
        //                    }

        //                }
        //                else
        //                {
        //                    addzhekoulv[i] = this.numericUpDown2.Value.ToString();
        //                    addzongjine[i] = (addprice[i] * addcount[i] * this.numericUpDown2.Value).ToString("F1");

        //                }



        //                break;
        //            }
        //            else if (addname[i] == this.cboGoods.Text)
        //            {
        //                break;
        //            }    
        //        }


        //                for (int j = 0; j < dataGridView1.RowCount; j++)
        //                {

        //                    if (this.cboGoods.Text.Equals(dataGridView1.Rows[j].Cells["goodsname"].Value.ToString()))
        //                    {
        //                        Model.goods gm = new Model.goods();
        //                        gm = g.GetModel(int.Parse(this.cboGoods.SelectedValue.ToString()));
        //                        addname[j] = gm.goodsName;
        //                        addprice[j] = (decimal)gm.price;
        //                        addcuxiaoprice[j] = decimal.Parse(gm.Promotionprice1);
        //                        addshifoucuxiao[j] = bool.Parse(gm.Promotion1);
        //                        addcount[j] = this.numericUpDown1.Value;
        //                        addteshuzhekou[j] = zhekou;
        //                        dataGridView1.Rows[j].Cells["count"].Value = int.Parse(dataGridView1.Rows[j].Cells["count"].Value.ToString()) + addcount[j];
        //                        if (this.button3.Text == "启用")
        //                        {
        //                            addzhekoulv[j] = (decimal.Parse(zhekoulv) / 10).ToString("F1");
        //                            addzongjine[j] = ((decimal)gm.price * this.numericUpDown1.Value * (decimal.Parse(zhekoulv) / 100)).ToString("F1");
        //                            dataGridView1.Rows[j].Cells["特殊折扣"].Value = zhekou;
        //                            dataGridView1.Rows[j].Cells["总金额"].Value = (decimal.Parse(dataGridView1.Rows[j].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView1.Rows[j].Cells["price"].Value.ToString()) * (decimal.Parse(zhekoulv) / 100)).ToString("F1");
        //                            dataGridView1.Rows[j].Cells["折扣率"].Value = addzhekoulv[j];
        //                        }
        //                        else
        //                        {

        //                            //addzongjine[j] = ((decimal)gm.price * this.numericUpDown1.Value * this.numericUpDown2.Value / 10).ToString("F1");


        //                            if (zhekou)
        //                            {
        //                                addzhekoulv[j] = this.numericUpDown2.Value.ToString("F1");
        //                                dataGridView1.Rows[j].Cells["折扣率"].Value = addzhekoulv[j];
        //                                dataGridView1.Rows[j].Cells["总金额"].Value = (decimal.Parse(dataGridView1.Rows[j].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView1.Rows[j].Cells["price"].Value.ToString()) * (this.numericUpDown2.Value / 10)).ToString("F1");  
        //                            }
        //                            else
        //                            {
        //                                addzhekoulv[j] = (decimal.Parse(zhekoulv) / 10).ToString("F1");
        //                                dataGridView1.Rows[j].Cells["总金额"].Value = (decimal.Parse(dataGridView1.Rows[j].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView1.Rows[j].Cells["price"].Value.ToString()) * (decimal.Parse(zhekoulv) / 100)).ToString("F1");
        //                                dataGridView1.Rows[j].Cells["折扣率"].Value = addzhekoulv[j];
        //                            }
        //                            dataGridView1.Rows[j].Cells["特殊折扣"].Value = zhekou;
        //                        }
        //                        decimal txtzongjine = 0m;
        //                        decimal txtzhehoujine = 0m;
        //                        for (int i = 0; i < dataGridView1.RowCount; i++)
        //                        {
        //                            if (bool.Parse(dataGridView1.Rows[i].Cells["Promotion"].Value.ToString()))
        //                            {
        //                                txtzongjine += decimal.Parse(dataGridView1.Rows[i].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView1.Rows[i].Cells["Promotionprice"].Value.ToString());
        //                                txtzhehoujine += decimal.Parse(dataGridView1.Rows[i].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView1.Rows[i].Cells["Promotionprice"].Value.ToString()) * (decimal.Parse(dataGridView1.Rows[i].Cells["折扣率"].Value.ToString()) / 10);

        //                            }
        //                            else
        //                            {
        //                                txtzongjine += decimal.Parse(dataGridView1.Rows[i].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView1.Rows[i].Cells["price"].Value.ToString());
        //                                txtzhehoujine += decimal.Parse(dataGridView1.Rows[i].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView1.Rows[i].Cells["price"].Value.ToString()) * (decimal.Parse(dataGridView1.Rows[i].Cells["折扣率"].Value.ToString()) / 10);

        //                            }
        //                        }

        //                        this.TxtConsume.Text = txtzongjine.ToString("F1");
        //                        this.TxtDiscountAmount.Text = txtzhehoujine.ToString("F1");

        //                        if (decimal.Parse(this.TxtDiscountAmount.Text) < decimal.Parse(this.TxtBalance.Text))
        //                        {
        //                            this.TxtCardPay.Text = this.TxtDiscountAmount.Text;
        //                        }
        //                        else
        //                        {
        //                            this.TxtCardPay.Text = this.TxtBalance.Text;
        //                            this.TxtCrashPay.Text = (decimal.Parse(this.TxtDiscountAmount.Text) - decimal.Parse(this.TxtBalance.Text)).ToString("F1");
        //                        }


        //                        //this.TxtConsume.Text = (decimal.Parse(this.TxtConsume.Text) + (addprice[j] * addcount[j])).ToString("F1");
        //                        Integral = buypart(decimal.Parse(this.TxtDiscountAmount.Text));

        //                        //if (this.button3.Text == "启用")
        //                        //{
        //                        //    this.TxtDiscountAmount.Text = buyzhekou(decimal.Parse(this.TxtConsume.Text)).ToString("F1");
        //                        //}
        //                        //else
        //                        //{
        //                        //    this.TxtDiscountAmount.Text = (decimal.Parse(this.TxtConsume.Text) * (this.numericUpDown2.Value / 10)).ToString("F1");
        //                        //}
        //                        //if (decimal.Parse(this.TxtDiscountAmount.Text) < decimal.Parse(this.TxtBalance.Text))
        //                        //{
        //                        //    this.TxtCardPay.Text = this.TxtDiscountAmount.Text;
        //                        //}
        //                        //else
        //                        //{
        //                        //    this.TxtCardPay.Text = this.TxtBalance.Text;
        //                        //    this.TxtCrashPay.Text = (decimal.Parse(this.TxtDiscountAmount.Text) - decimal.Parse(this.TxtBalance.Text)).ToString("F1");
        //                        //}
        //                        return;
        //                    }

        //                }
        //                for (int j = 0; j < addname.Length; j++)
        //                    {
        //                        Model.goods gm1 = new Model.goods();
        //                        gm1 = g.GetModel(int.Parse(this.cboGoods.SelectedValue.ToString()));
        //                        addname[j] = gm1.goodsName;
        //                        addprice[j] = (decimal)gm1.price;
        //                        addcuxiaoprice[j] = decimal.Parse(gm1.Promotionprice1);
        //                        addshifoucuxiao[j] = bool.Parse(gm1.Promotion1);
        //                        addcount[j] = this.numericUpDown1.Value;
        //                        addteshuzhekou[j] = zhekou;
        //                        if (this.button3.Text == "启用")
        //                        {
        //                            addzhekoulv[j] = (decimal.Parse(zhekoulv) / 10).ToString("F1");
        //                            if (addshifoucuxiao[j] == true)
        //                            {
        //                                addzongjine[j] = (addcuxiaoprice[j] * addcount[j] * (decimal.Parse(zhekoulv) / 100)).ToString("F1");
        //                            }
        //                            else
        //                            {
        //                                addzongjine[j] = (addprice[j] * addcount[j] * (decimal.Parse(zhekoulv) / 100)).ToString("F1");
        //                            }
        //                        }
        //                        else
        //                        {
        //                            addzhekoulv[j] = this.numericUpDown2.Value.ToString("F1");
        //                            addzongjine[j] = ((decimal)gm1.price * this.numericUpDown1.Value * this.numericUpDown2.Value/10).ToString("F1");
        //                        }


        //                        if (addname[j]!=null)
        //                        {

        //                            string[] addgood = { addname[j], addprice[j].ToString("F1"),addcuxiaoprice[j].ToString("F1"),addshifoucuxiao[j].ToString(), addcount[j].ToString(), addteshuzhekou[j].ToString(), addzhekoulv[j], addzongjine[j] };
        //                            dataGridView1.Rows.Add(addgood);

        //                            for (int i = 0; i < dataGridView1.Rows.Count; i++)
        //                            {
        //                                if (bool.Parse(dataGridView1.Rows[i].Cells["Promotion"].Value.ToString()))
        //                                {
        //                                    dataGridView1.Rows[i].Cells["price"].Value = "-";
        //                                }
        //                                else
        //                                {
        //                                    dataGridView1.Rows[i].Cells["Promotionprice"].Value = "-";
        //                                }
        //                            }


        //                            decimal txtzongjine = 0m;
        //                            decimal txtzhehoujine = 0m;
        //                            for (int i = 0; i < dataGridView1.RowCount; i++)
        //                            {
        //                                if (bool.Parse(dataGridView1.Rows[i].Cells["Promotion"].Value.ToString()))
        //                                {
        //                                    txtzongjine += decimal.Parse(dataGridView1.Rows[i].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView1.Rows[i].Cells["Promotionprice"].Value.ToString());
        //                                    txtzhehoujine += decimal.Parse(dataGridView1.Rows[i].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView1.Rows[i].Cells["Promotionprice"].Value.ToString()) * (decimal.Parse(dataGridView1.Rows[i].Cells["折扣率"].Value.ToString()) / 10);

        //                                }
        //                                else
        //                                {
        //                                    txtzongjine += decimal.Parse(dataGridView1.Rows[i].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView1.Rows[i].Cells["price"].Value.ToString());
        //                                    txtzhehoujine += decimal.Parse(dataGridView1.Rows[i].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView1.Rows[i].Cells["price"].Value.ToString()) * (decimal.Parse(dataGridView1.Rows[i].Cells["折扣率"].Value.ToString()) / 10);

        //                                }

        //                            }

        //                            this.TxtConsume.Text = txtzongjine.ToString("F1");
        //                            this.TxtDiscountAmount.Text = txtzhehoujine.ToString("F1");

        //                            if (decimal.Parse(this.TxtDiscountAmount.Text) < decimal.Parse(this.TxtBalance.Text))
        //                            {
        //                                this.TxtCardPay.Text = this.TxtDiscountAmount.Text;
        //                            }
        //                            else
        //                            {
        //                                this.TxtCardPay.Text = this.TxtBalance.Text;
        //                                this.TxtCrashPay.Text = (decimal.Parse(this.TxtDiscountAmount.Text) - decimal.Parse(this.TxtBalance.Text)).ToString("F1");
        //                            }


        //                            //this.TxtConsume.Text = (decimal.Parse(this.TxtConsume.Text) + (addprice[j] * addcount[j])).ToString("F1");
        //                            Integral = buypart(decimal.Parse(this.TxtDiscountAmount.Text));

        //                            //if (decimal.Parse(this.TxtDiscountAmount.Text) < decimal.Parse(this.TxtBalance.Text))
        //                            //{
        //                            //    this.TxtCardPay.Text = this.TxtDiscountAmount.Text;
        //                            //}
        //                            //else
        //                            //{
        //                            //    this.TxtCardPay.Text = this.TxtBalance.Text;
        //                            //    this.TxtCrashPay.Text = (decimal.Parse(this.TxtDiscountAmount.Text) - decimal.Parse(this.TxtBalance.Text)).ToString("F1");
        //                            //}
        //                            //if (this.button3.Text == "启用")
        //                            //{
        //                            //    this.TxtDiscountAmount.Text = buyzhekou(decimal.Parse(this.TxtConsume.Text)).ToString("F1");
        //                            //}
        //                            //else
        //                            //{
        //                            //    this.TxtDiscountAmount.Text = (decimal.Parse(this.TxtConsume.Text) * (this.numericUpDown2.Value / 10)).ToString("F1");
        //                            //}
        //                            return;
        //                        }

        //                    }







        //        }

        //    }


        private void timer1_Tick(object sender, EventArgs e)
        {
            //timer开启
            this.Left += 2;
            this.Opacity += 0.1;
            if (Opacity == 1)
            {
                this.timer1.Stop();
            }
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            //timer关闭
            this.Top = this.Top + 10;
            this.Opacity = this.Opacity - 0.06;
            if (Opacity <= 0)
            {
                this.timer2.Stop();
                this.Close();

            }
        }
        int flag = 0;
        private void MemberSaleForm_FormClosing(object sender, FormClosingEventArgs e)
        {

            if (flag == 0)
            {
                e.Cancel = true;
                flag = 1;
                this.timer2.Start();
            }

        }

        //private void TxtConsume_TextChanged(object sender, EventArgs e)
        //{
        //    if (this.TxtConsume.Text == "")
        //    {
        //        this.TxtConsume.Text = "0";
        //        this.TxtCrashPay.Text = "0";
        //    }
        //    try
        //    {
        //        decimal.Parse(this.TxtConsume.Text);
        //    }
        //    catch (Exception)
        //    {
        //        MessageBox.Show("请输入有效的金额");
        //        this.TxtConsume.Text = "0";
        //        return;
        //    }

        //    for (int i = 0; i < addname.Length; i++)
        //    {
        //        Model.goods gm = new Model.goods();
        //        gm = g.GetModel(int.Parse(this.cboGoods.SelectedValue.ToString()));
        //        addname[i] = gm.goodsName;
        //        addprice[i] = (decimal)gm.price;
        //        if (this.button3.Text == "启用")
        //        {
        //            this.TxtDiscountAmount.Text = buyzhekou(decimal.Parse(this.TxtConsume.Text)).ToString("F1");
        //        }
        //        else
        //        {
        //            this.TxtDiscountAmount.Text = (decimal.Parse(this.TxtConsume.Text) * (this.numericUpDown2.Value / 10)).ToString("F1");
        //        }
        //        Integral = buypart(decimal.Parse(this.TxtDiscountAmount.Text));
        //        if (decimal.Parse(this.TxtDiscountAmount.Text) < decimal.Parse(this.TxtBalance.Text))
        //        {
        //            this.TxtCardPay.Text = this.TxtDiscountAmount.Text;

        //            this.TxtCrashPay.Text = "0";


        //        }
        //        else
        //        {
        //            this.TxtCardPay.Text = this.TxtBalance.Text;
        //            this.TxtCrashPay.Text = (decimal.Parse(this.TxtDiscountAmount.Text) - decimal.Parse(this.TxtBalance.Text)).ToString("F1");
        //        }
        //        string[] addgood = { addname[i], addprice[i].ToString(), addcount[i].ToString() };

        //        return;

        //    }
        //}

        string[] jianname = new string[100];
        decimal[] jianprice = new decimal[100];
        decimal[] jiancount = new decimal[100];

        private void TxtCardId_Leave(object sender, EventArgs e)
        {
            if (this.TxtCardId.Text == "")
            {
                read();
            }
            else
            {
                memberInfo member = new memberInfo();
                ZG_member.Model.memberInfo memberMode = new ZG_member.Model.memberInfo();
                memberMode = member.GetModels(this.TxtCardId.Text);
                if (memberMode != null)
                {
                    this.TxtCardId.Text = memberMode.memberId;
                    this.TxtName.Text = memberMode.memberName;
                    this.TxtBalance.Text = memberMode.Balance.ToString();
                    this.TxtIntegral.Text = memberMode.point.ToString();
                    this.txtzhifuhoujifen.Text = memberMode.point.ToString();
                    BLL.goods goodbll = new BLL.goods();
                    BLL.taocanjiluBLL tcbll = new taocanjiluBLL();
                    Model.taocanjilu tcmodle = tcbll.GetModelFormemberCardId(this.TxtCardId.Text);
                    if (tcmodle == null)
                    {
                        return;
                    }
                    if (tcmodle.Xiangqing != null)
                    {
                        if (tcmodle.Xiangqing != "" && tcmodle.Xiangqing != null)
                        {
                            for (int p = 0; p < dataGridView1.Rows.Count; p++)
                            {
                                this.dataGridView1.Rows.Remove(this.dataGridView1.Rows[p]);
                            }
                            string[] liebiao = tcmodle.Xiangqing.Split('|');
                            for (int i = 0; i < liebiao.Length; i++)
                            {
                                if (liebiao[i] == "")
                                {
                                    return;
                                }
                                string[] liebiaoxiangqing = liebiao[i].Split(',');
                                Model.goods goodmodle = goodbll.getModelGoodsIdString(liebiaoxiangqing[0]);
                                if (goodmodle == null)
                                {
                                    continue;
                                }
                                string[] jiazailiebiao = { liebiaoxiangqing[0], goodmodle.goodsName, liebiaoxiangqing[1],goodmodle.unit };
                                this.dataGridView1.Rows.Add(jiazailiebiao);
                            }
                        }
                    }
                }
                else
                {
                    MessageBox.Show("没有找到该会员");
                    this.TxtCardId.Text = memberID;
                }
            }

        }

        private void button3_Click(object sender, EventArgs e)
        {



            if (this.button3.Text == "启用")
            {
                Model.operatorInfo o = new Model.operatorInfo();
                operatorInfo ot = new operatorInfo();
                //string passWord = this.textBox2.Text;
                //MD5 md5 = new MD5CryptoServiceProvider();
                //byte[] bt = Encoding.Default.GetBytes(passWord);
                //bt = md5.ComputeHash(bt);
                //passWord = BitConverter.ToString(bt).Replace("-", "");

                try
                {
                    o = ot.GetModelList(" username = '" + MainForm.Operator + "'")[0];
                }
                catch (Exception)
                {

                    MessageBox.Show("折扣启用失败！");
                    return;
                }

                Model.roleInfo r = new Model.roleInfo();
                roleInfo ri = new roleInfo();
                r = ri.GetModel((int)o.roleId);

                if (r.Specialrebate == "1")
                {
                    this.numericUpDown2.Enabled = true;
                    this.button3.Text = "关闭";
                }
                else
                {
                    specialrebate sl = new specialrebate();
                    sl.ShowDialog();
                    if (sl.aa == 1)
                    {
                        this.numericUpDown2.Enabled = true;
                        this.button3.Text = "关闭";
                    }
                    else
                    {
                        if (sl.aa == 3)
                        {
                            return;
                        }
                        //MessageBox.Show("特殊折扣启用未成功！原因：您并非特殊折扣管理员！");
                    }
                }



            }
            else if (this.button3.Text == "关闭")
            {
                this.numericUpDown2.Enabled = false;
                this.button3.Text = "启用";
            }

        }

        //private void numericUpDown2_ValueChanged(object sender, EventArgs e)
        //{
        //    //if (this.TxtConsume.Text == "")
        //    //{
        //    //    this.TxtConsume.Text = "0";
        //    //    this.TxtCrashPay.Text = "0";
        //    //}
        //    //try
        //    //{
        //    //    decimal.Parse(this.TxtConsume.Text);
        //    //}
        //    //catch (Exception)
        //    //{
        //    //    MessageBox.Show("请输入有效的金额");
        //    //    this.TxtConsume.Text = "0";
        //    //    return;
        //    //}

        //    for (int i = 0; i < addname.Length; i++)
        //    {
        //        Model.goods gm = new Model.goods();
        //        gm = g.GetModel(int.Parse(this.cboGoods.SelectedValue.ToString()));
        //        addname[i] = gm.goodsName;
        //        addprice[i] = (decimal)gm.price;
        //        if (this.button3.Text == "启用")
        //        {
        //            this.TxtDiscountAmount.Text = buyzhekou(decimal.Parse(this.TxtConsume.Text)).ToString("F1");
        //        }
        //        else
        //        {
        //            this.TxtDiscountAmount.Text = (decimal.Parse(this.TxtConsume.Text) * (this.numericUpDown2.Value / 10)).ToString("F1");
        //        }
        //        Integral = buypart(decimal.Parse(this.TxtDiscountAmount.Text));
        //        if (decimal.Parse(this.TxtDiscountAmount.Text) < decimal.Parse(this.TxtBalance.Text))
        //        {
        //            this.TxtCardPay.Text = this.TxtDiscountAmount.Text;

        //            this.TxtCrashPay.Text = "0";


        //        }
        //        else
        //        {
        //            this.TxtCardPay.Text = this.TxtBalance.Text;
        //            this.TxtCrashPay.Text = (decimal.Parse(this.TxtDiscountAmount.Text) - decimal.Parse(this.TxtBalance.Text)).ToString("F1");
        //        }
        //        string[] addgood = { addname[i], addprice[i].ToString(), addcount[i].ToString() };

        //        return;

        //    }
        //}

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (this.checkBox1.Checked)
            {
                try
                {
                    HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://sdk2.entinfo.cn:8060/webservice.asmx");
                    HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
                    if (resp.StatusCode == HttpStatusCode.OK)
                    {
                        resp.Close();

                    }
                    else
                    {

                    }
                }
                catch (WebException webex)
                {
                    //this.timer5.Stop();
                    this.checkBox1.Checked = false;
                    MessageBox.Show("由于您的计算机未连网！将无法发送短信！");

                }
            }
        }

        private void TxtConsume_TextChanged(object sender, EventArgs e)
        {
            //if (this.TxtConsume.Text == "")
            //{
            //    this.TxtConsume.Text = "0";
            //    this.TxtCrashPay.Text = "0";
            //}
            //try
            //{
            //    decimal.Parse(this.TxtConsume.Text);
            //}
            //catch (Exception)
            //{
            //    MessageBox.Show("请输入有效的金额");
            //    this.TxtConsume.Text = "0";
            //    return;
            //}

            //for (int i = 0; i < addname.Length; i++)
            //{
            //    //Model.goods gm = new Model.goods();
            //    //gm = g.GetModel(int.Parse(this.cboGoods.SelectedValue.ToString()));
            //    //addname[i] = gm.goodsName;
            //    //addprice[i] = (decimal)gm.price;
            //    if (this.button3.Text == "启用")
            //    {
            //        this.TxtDiscountAmount.Text = buyzhekou(decimal.Parse(this.TxtConsume.Text)).ToString("F1");
            //    }
            //    else
            //    {
            //        this.TxtDiscountAmount.Text = (decimal.Parse(this.TxtConsume.Text) * (this.numericUpDown2.Value / 10)).ToString("F1");
            //    }

            //    if (decimal.Parse(this.TxtDiscountAmount.Text) < decimal.Parse(this.TxtBalance.Text))
            //    {
            //        this.TxtCardPay.Text = this.TxtDiscountAmount.Text;

            //        this.TxtCrashPay.Text = "0";


            //    }
            //    else
            //    {
            //        //(decimal.Parse(this.TxtBalance.Text) - decimal.Parse(this.txtjifenzhifu.Text)).ToString();
            //        this.TxtCardPay.Text = this.TxtBalance.Text;
            //        this.TxtCrashPay.Text = (decimal.Parse(this.TxtDiscountAmount.Text) - decimal.Parse(this.TxtBalance.Text) - decimal.Parse(this.txtjifenzhifu.Text)).ToString("F1");
            //    }
            //    Integral = buypart(decimal.Parse(this.TxtCardPay.Text) + decimal.Parse(this.TxtCrashPay.Text));
            //    this.txtzhifuhoujifen.Text = (decimal.Parse(this.TxtIntegral.Text) + decimal.Parse(Integral)).ToString("F0");
            //    string[] addgood = { addname[i], addprice[i].ToString(), addcount[i].ToString() };

            //    return;

            //}













        }

        private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {

            if (int.Parse(dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["goodcount"].Value.ToString()) <= 0)
            {
                MessageBox.Show("该商品已兑换完！");
                return;
            }
            goodcount gc = new goodcount(int.Parse(dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["goodcount"].Value.ToString()), this);
            gc.ShowDialog();

            //for (int i = 0; i < dataGridView2.Rows.Count; i++)
            //{
            //    if (dataGridView2.Rows.Count <=0)
            //    {
            //        break;
            //    }
            //    if (dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["goodname"].Value.ToString() == dataGridView2.Rows[i].Cells["goodsname"].Value.ToString())
            //    {

            //        //dataGridView1.Rows[i].Cells["goodcount"].Value = int.Parse(dataGridView1.Rows[i].Cells["goodcount"].Value.ToString()) + int.Parse(this.numericUpDown1.Value.ToString());
            //        return;
            //    }
            //}
            //string[] tiaojian = { dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["goodsid"].Value.ToString(), dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["goodname"].Value.ToString(), dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["goodcount"].Value.ToString() };
            //dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["goodcount"].Value = "0";
            //this.dataGridView2.Rows.Add(tiaojian);
        }

        private void dataGridView2_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            // dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["goodcount"].Value = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["goodcount"].Value;
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if (dataGridView1.Rows[i].Cells["goodname"].Value == dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["goodsname"].Value)
                {
                    dataGridView1.Rows[i].Cells["goodcount"].Value = dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["goodscount"].Value;
                    break;
                }
            }
            this.dataGridView2.Rows.RemoveAt(dataGridView2.CurrentRow.Index);
        }

        private void btnAllAdd_Click(object sender, EventArgs e)
        {
            if (dataGridView2.Rows.Count > 0)
            {
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    for (int j = 0; j < dataGridView2.Rows.Count; j++)
                    {
                        if (decimal.Parse(dataGridView1.Rows[i].Cells["goodcount"].Value.ToString()) == 0)
                        {
                            continue;
                        }
                        if (dataGridView2.Rows.Count > 0)
                        {
                            if (dataGridView1.Rows[i].Cells["goodname"].Value.ToString() == dataGridView2.Rows[j].Cells["goodsname"].Value.ToString())
                            {
                                dataGridView2.Rows[j].Cells["goodscount"].Value = decimal.Parse(dataGridView2.Rows[j].Cells["goodscount"].Value.ToString()) + decimal.Parse(dataGridView1.Rows[i].Cells["goodcount"].Value.ToString());
                                dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["goodcount"].Value = "0";
                                break;
                            }

                            //string[] tianjiaall = { dataGridView1.Rows[i].Cells["goodsid"].Value.ToString(), dataGridView1.Rows[i].Cells["goodname"].Value.ToString(), dataGridView1.Rows[i].Cells["goodcount"].Value.ToString() };
                            //dataGridView2.Rows.Add(tianjiaall);
                            //dataGridView1.Rows[i].Cells["goodcount"].Value = "0";
                            //continue;
                        }

                        string[] tianjiaall1 = { dataGridView1.Rows[i].Cells["goodsid"].Value.ToString(), dataGridView1.Rows[i].Cells["goodname"].Value.ToString(), dataGridView1.Rows[i].Cells["goodcount"].Value.ToString(), dataGridView1.Rows[i].Cells["danwei"].Value.ToString() };
                        dataGridView2.Rows.Add(tianjiaall1);
                        dataGridView1.Rows[i].Cells["goodcount"].Value = "0";



                    }
                }
            }
            else
            {
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    if (decimal.Parse(dataGridView1.Rows[i].Cells["goodcount"].Value.ToString()) == 0)
                    {
                        continue;
                    }
                    string[] tianjiaall1 = { dataGridView1.Rows[i].Cells["goodsid"].Value.ToString(), dataGridView1.Rows[i].Cells["goodname"].Value.ToString(), dataGridView1.Rows[i].Cells["goodcount"].Value.ToString() };
                    dataGridView2.Rows.Add(tianjiaall1);
                    dataGridView1.Rows[i].Cells["goodcount"].Value = "0";
                }
            }



        }

        private void btnAllclear_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < dataGridView2.Rows.Count; i++)
            {
                for (int j = 0; j < dataGridView1.Rows.Count; j++)
                {
                    if (dataGridView2.Rows[i].Cells["goodsname"].Value.ToString() == dataGridView1.Rows[j].Cells["goodname"].Value.ToString())
                    {
                        dataGridView1.Rows[j].Cells["goodcount"].Value = decimal.Parse(dataGridView1.Rows[j].Cells["goodcount"].Value.ToString()) + decimal.Parse(dataGridView2.Rows[i].Cells["goodscount"].Value.ToString());

                        break;
                    }
                }
            }
            dataGridView2.Rows.Clear();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

            if (this.txtjifenzhifu.Text == "" || this.txtjifenzhifu.Text == null)
            {
                this.txtjifenzhifu.Text = "0";
                return;
            }
            if (decimal.Parse(this.txtjifenzhifu.Text) <= (decimal.Parse(this.TxtConsume.Text) - decimal.Parse(this.TxtCardPay.Text)))
            {
                this.TxtCrashPay.Text = ((int)decimal.Parse(this.TxtConsume.Text) - decimal.Parse(this.TxtCardPay.Text) - decimal.Parse(this.txtjifenzhifu.Text)).ToString();
                Integral = buypart(decimal.Parse(this.TxtCardPay.Text) + decimal.Parse(this.TxtCrashPay.Text));
                this.txtzhifuhoujifen.Text = (decimal.Parse(this.TxtIntegral.Text) - decimal.Parse(this.txtjifenzhifu.Text) + decimal.Parse(Integral)).ToString("F0");
            }
            else
            {
                this.txtjifenzhifu.Text = (decimal.Parse(this.TxtConsume.Text) - decimal.Parse(this.TxtCardPay.Text)).ToString("F0");
            }
            if (int.Parse(this.TxtIntegral.Text) < decimal.Parse(this.txtjifenzhifu.Text))
            {
                //this.txtjifenzhifu.Text = this.TxtIntegral.Text;
                return;
            }






        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!(Char.IsNumber(e.KeyChar)) && e.KeyChar != (char)13 && e.KeyChar != (char)8)
            {
                e.Handled = true;
            }
        }

        private void TxtCardId_TextChanged(object sender, EventArgs e)
        {
            //int status = VN.StatusDemand();
            //if (status != 0x02)
            //{

            //}
            //else
            //{
            //    string data = "";
            //    byte blocknum = 1;
            //    //VN.WriteData(blocknum, data);
            //    //return;
            //    VN.ReadData(blocknum, ref data);
            //    this.TxtCardId.Text = data;
            //    id = this.TxtCardId.Text;
            //}

            memberInfo member = new memberInfo();
            Model.memberInfo memberMod = new Model.memberInfo();
            try
            {
                //if (status != 0x02)
                //{
                memberMod = member.GetModels(this.TxtCardId.Text.Trim());
                //}
                //else
                //{
                //    memberMod = member.GetModelList("memberCardId='" + this.TxtCardId.Text + "'")[0];
                //}

            }
            catch
            {
                this.TxtCardId.Text = "";
                MessageBox.Show("找不到该会员");

                return;
            }
            if (memberMod == null)
            {
                if (this.TxtName.Text == "")
                {
                    this.TxtConsume.Enabled = false;
                    //this.button1.Enabled = false;
                    //this.button2.Enabled = false;

                }
                else
                {
                    this.TxtConsume.Enabled = true;
                    //this.button1.Enabled = true;
                    //this.button2.Enabled = true;
                }
                return;

            }
            if (!test(memberMod))
            {
                this.Close();
                return;
            }


            TxtCardId.Text = memberMod.memberId;
            TxtName.Text = memberMod.memberName;
            TxtIntegral.Text = memberMod.point.ToString();
            TxtBalance.Text = memberMod.Balance.Value.ToString("F1");
            this.txtzhifuhoujifen.Text = memberMod.point.ToString();
            //this.cboGoods.DataSource = getgood();
            //this.cboGoods.DisplayMember = "goodsName";
            //this.cboGoods.ValueMember = "id";
            //if (this.TxtName.Text == "")
            //{
            //    this.TxtConsume.Enabled = false;
            //    this.button1.Enabled = false;
            //    this.button2.Enabled = false;

            //}
            //else
            //{
            //    this.TxtConsume.Enabled = true;
            //    this.button1.Enabled = true;
            //    this.button2.Enabled = true;
            //}
        }

        //public string getzhekoulv()
        //{
        //    Model.consumeSolution cm = new Model.consumeSolution();
        //    memberInfo m = new memberInfo();
        //    Model.memberInfo mi = m.GetModels(this.TxtCardId.Text);
        //    int idd = (int)mi.cardType;
        //    goods g = new goods();
        //    string discountSolution = "";
        //    //Model.goods gm = g.GetModelList(" goodsname = '" + dataGridView1.Rows[j].Cells["count"].Value.ToString() + "'")[0];
        //    cm = cs.GetModel((int)mi.cardType);
        //    //string discountSolution = cm.discountSolution;
        //    try
        //    {
        //        Model.goods gm = g.GetModelList(" goodsname = '" + this.cboGoods.Text + "'")[0];


        //        discountSolution = cm.discountSolution;

        //        if (Convert.ToBoolean(gm.Promotion))
        //        {
        //            if (cm.solutionName != "金卡")
        //            {
        //                discountSolution = gm.lowestOff;
        //                return discountSolution;
        //            }
        //            else
        //            {
        //                discountSolution = "100";
        //                return discountSolution;
        //            }
        //        }

        //    }
        //    catch
        //    {
        //        this.numericUpDown1.Value = 0;
        //        MessageBox.Show("商品添加出错，请确定商品列表中有此商品");
        //    }


        //    //cm = cs.GetModel((int)mi.cardType);
        //    //string yaa = "白金卡";
        //    //string jaa = "金卡";

        //    //if (cm.solutionName.IndexOf(yaa) > -1)
        //    //{
        //    //    if (cm.discountSolution == "100")
        //    //    {
        //    //        discountSolution = gm.Silverdiscount;
        //    //    }
        //    //    else if (gm.Silverdiscount == "100")
        //    //    {
        //    //        discountSolution = cm.discountSolution;
        //    //    }
        //    //    else
        //    //    {
        //    //        string aaaa = (decimal.Parse(cm.discountSolution) * decimal.Parse(gm.Silverdiscount)).ToString("F1");
        //    //        discountSolution = aaaa.Substring(0, 2);
        //    //        if (!(int.Parse(discountSolution) > 10))
        //    //        {
        //    //            discountSolution = (decimal.Parse(discountSolution) * 10).ToString("F1");
        //    //        }
        //    //        else
        //    //        {

        //    //        }

        //    //    }


        //    //}
        //    //else if (cm.solutionName.IndexOf(jaa) > -1)
        //    //{
        //    //    if (cm.discountSolution == "100")
        //    //    {
        //    //        discountSolution = gm.Golddiscount;
        //    //    }
        //    //    else if (gm.Golddiscount == "100")
        //    //    {
        //    //        discountSolution = cm.discountSolution;
        //    //    }
        //    //    else
        //    //    {
        //    //        string aaaa = (decimal.Parse(cm.discountSolution) * decimal.Parse(gm.Golddiscount)).ToString("F1");
        //    //        discountSolution = aaaa.Substring(0, 2);
        //    //        if (!(int.Parse(discountSolution) > 10))
        //    //        {
        //    //            discountSolution = (decimal.Parse(discountSolution) * 10).ToString("F1");
        //    //        }
        //    //        else
        //    //        {

        //    //        }


        //    //    }


        //    // }



        //    //birthdayremind br = new birthdayremind();
        //    //Model.birthdayremind brmodl = br.GetModel(2);
        //    //int aa = br.tixingday(this.TxtCardId.Text);
        //    //string[] shengrijifen = brmodl.Birthdaydiscount.Split();
        //    //if (aa == 0)
        //    //{
        //    //    discountSolution = brmodl.Birthdaydiscount;
        //    //}
        //    return discountSolution;
        //}

        public string getzhekoulvshangpin()
        {
            ZG_member.BLL.goods goods = new ZG_member.BLL.goods();
            ZG_member.Model.goods goodsMode = new ZG_member.Model.goods();
            ZG_member.BLL.memberInfo member = new ZG_member.BLL.memberInfo();
            ZG_member.Model.memberInfo memberMode = new ZG_member.Model.memberInfo();
            ZG_member.BLL.consumeSolution consume = new ZG_member.BLL.consumeSolution();
            ZG_member.Model.consumeSolution consumeMode = new ZG_member.Model.consumeSolution();
            memberMode = member.GetModeCard(id);
            if (id == "0")
            {
                memberMode = member.GetModels(memberId);
            }
            if (memberMode == null)
            {
                MessageBox.Show("未找到该会员");
                return "false";
            }
                goodsMode = goods.GetModelName(this.cboGoods.Text);
                consumeMode = consume.GetModel(Convert.ToInt32(memberMode.cardType));
                if (consumeMode.cuxiaozhekou == true && goodsMode.Promotion == true)
                {
                    return goodsMode.Promotionprice;
                }
                else
                {
                    //if (goodsMode.GlobalDiscount == true)
                    //{
                    //    return goodsMode.Promotionprice;
                    //}
                    //else
                    //{
                    //    return "100";
                    //}
                    return "100";
                }
          
        }



        public string getzhekoulv()
        {
            ZG_member.BLL.goods goods = new ZG_member.BLL.goods();
            ZG_member.Model.goods goodsMode = new ZG_member.Model.goods();
            ZG_member.BLL.memberInfo member = new ZG_member.BLL.memberInfo();
            ZG_member.Model.memberInfo memberMode = new ZG_member.Model.memberInfo();
            ZG_member.BLL.consumeSolution consume = new ZG_member.BLL.consumeSolution();
            ZG_member.Model.consumeSolution consumeMode = new ZG_member.Model.consumeSolution();
            memberMode = member.GetModeCard(id);
            if (this.dataGridView3.Rows.Count > 0)
            {
                goodsMode = goods.GetModelName(this.cboGoods.Text);
                consumeMode = consume.GetModel(Convert.ToInt32(memberMode.cardType));
                if (consumeMode.cuxiaozhekou == true && goodsMode.Promotion == true)
                {
                    return goodsMode.Promotionprice;
                }
                else
                {
                    //if (goodsMode.GlobalDiscount == true)
                    //{
                    //    return goodsMode.Promotionprice;
                    //}
                    //else
                    //{
                    //    return "100";
                    //}
                    return "100";
                }
            }
            else
            {
                return "100";
            }
        }



        private void button2_Click(object sender, EventArgs e)
        {
            if (dataGridView3.Rows.Count == 0)
            {
                return;
            }
            int j = dataGridView3.CurrentRow.Index;
            dataGridView3.Rows.RemoveAt(j);
            if (dataGridView3.Rows.Count == 0)
            {
                this.TxtConsume.Text = "0";
                this.TxtDiscountAmount.Text = "0";
                this.TxtCrashPay.Text = "0";
                this.TxtCardPay.Text = "0";
                return;
            }
            //decimal jiage = decimal.Parse(dataGridView1.Rows[i].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView1.Rows[i].Cells["price"].Value.ToString()) *  decimal.Parse(dataGridView1.Rows[i].Cells["折扣率"].Value.ToString());
            //this.TxtConsume.Text = (decimal.Parse(this.TxtConsume.Text) - jiage).ToString("F1");
            //TxtDiscountAmount.Text = (buyzhekou(decimal.Parse(this.TxtConsume.Text))).ToString("F1");
            decimal txtzongjine = 0m;
            decimal txtzhehoujine = 0m;
            for (int i = 0; i < dataGridView3.RowCount; i++)
            {
                txtzongjine += decimal.Parse(dataGridView3.Rows[i].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView3.Rows[i].Cells["price"].Value.ToString());
                txtzhehoujine += decimal.Parse(dataGridView3.Rows[i].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView3.Rows[i].Cells["price"].Value.ToString()) * (decimal.Parse(dataGridView3.Rows[i].Cells["折扣率"].Value.ToString()) / 10);
            }

            this.TxtConsume.Text = txtzongjine.ToString("F1");
            this.TxtDiscountAmount.Text = txtzhehoujine.ToString("F1");
            if (decimal.Parse(this.TxtDiscountAmount.Text) < decimal.Parse(this.TxtBalance.Text))
            {
                this.TxtCardPay.Text = this.TxtDiscountAmount.Text;
            }
            else
            {
                this.TxtCardPay.Text = this.TxtBalance.Text;
                this.TxtCrashPay.Text = (decimal.Parse(this.TxtDiscountAmount.Text) - decimal.Parse(this.TxtBalance.Text)).ToString("F1");
            }



        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            string zhekoulv = getzhekoulvshangpin();
            if (zhekoulv == "false")
            {
                return;
            }
            bool zhekou = false;

            if (this.button3.Text != "启用")
            {
                DialogResult dt = MessageBox.Show("请问您是否使用特殊折扣？", "温馨提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
                if (dt == DialogResult.Yes)
                {
                    zhekou = true;
                }
            }



            if (this.cboGoods.Text == null)
            {
                MessageBox.Show("请选择商品！");
            }
            else if (Convert.ToInt32(this.numericUpDown1.Text) == 0 || this.numericUpDown1.Text == "")
            {
                MessageBox.Show("请输入数量！");
            }
            else
            {
                Model.goods goodmd = g.GetModel(g.GetbyId(this.cboGoods.Text));
                if (goodmd == null)
                {
                    return;
                }
                if (goodmd.amount < Convert.ToInt32(this.numericUpDown1.Text))
                {
                    MessageBox.Show("该商品数量不足！");
                    return;
                }
                if (dataGridView3.RowCount > 0)
                {
                    for (int i = 0; i < dataGridView3.Rows.Count; i++)
                    {
                        if (goodmd.goodsName == dataGridView3.Rows[i].Cells["gdsname"].Value.ToString())
                        {
                            if (goodmd.amount < (int.Parse(dataGridView3.Rows[i].Cells["count"].Value.ToString()) + Convert.ToInt32(this.numericUpDown1.Text)))
                            {
                                MessageBox.Show(dataGridView3.Rows[i].Cells["gdsname"].Value.ToString() + "该商品数量不足！");
                                return;
                            }
                        }

                    }

                }
                #region 计算提成

                if (this.button3.Text == "启用")
                {
                    if (goodmd.tichengType == "正常")
                    {
                        tichengMoney =tichengMoney+ Convert.ToDouble(zhekoulv)/100 * Convert.ToDouble(goodmd.price) * Convert.ToInt32(this.numericUpDown1.Text);
                    }
                    if (goodmd.tichengType == "负成本")
                    {
                        tichengMoney = tichengMoney - (goodmd.finalCost - Convert.ToDouble(zhekoulv)/100 * Convert.ToDouble(goodmd.price))*Convert.ToInt32(this.numericUpDown1.Text)*-1;
                    }
                }
                else
                {
                    if (goodmd.tichengType == "正常")
                    {
                        tichengMoney = tichengMoney + Convert.ToDouble(numericUpDown2.Value) * Convert.ToDouble(goodmd.price) * Convert.ToInt32(this.numericUpDown1.Text);
                    }
                    if (goodmd.tichengType == "负成本")
                    {
                        tichengMoney = tichengMoney - (goodmd.finalCost - Convert.ToDouble(numericUpDown2.Value) * Convert.ToDouble(goodmd.price)) * Convert.ToInt32(this.numericUpDown1.Text)*-1;
                    }
                }

                #endregion

                for (int i = 0; i < addname.Length; i++)
                {
                    if (addname[i] == null)
                    {
                        Model.goods gm = new Model.goods();
                        gm = g.GetModel(int.Parse(this.cboGoods.SelectedValue.ToString()));
                        addname[i] = gm.goodsName;
                        addprice[i] = (decimal)gm.price;
                        addcuxiaoprice[i] = (decimal)gm.price*(decimal.Parse(gm.Promotionprice)/100);
                        addshifoucuxiao[i] =Convert.ToBoolean(gm.Promotion);
                        addcount[i] = Convert.ToInt32(this.numericUpDown1.Text);
                        addteshuzhekou[i] = zhekou;
                        if (this.button3.Text == "启用")
                        {
                            addzhekoulv[i] = (decimal.Parse(zhekoulv) / 10).ToString();
                            if (addshifoucuxiao[i] == true)
                            {
                                //addzongjine[i] = (addcuxiaoprice[i] * addcount[i] * (decimal.Parse(zhekoulv) / 100)).ToString("F1");
                                addzongjine[i] = (addcuxiaoprice[i] * addcount[i] ).ToString("F1");
                            }
                            else
                            {
                                addzongjine[i] = (addprice[i] * addcount[i] * (decimal.Parse(zhekoulv) / 100)).ToString("F1");
                            }

                        }
                        else
                        {
                            addzhekoulv[i] = this.numericUpDown2.Value.ToString();
                            addzongjine[i] = (addprice[i] * addcount[i] * this.numericUpDown2.Value).ToString("F1");

                        }



                        break;
                    }
                    else if (addname[i] == this.cboGoods.Text)
                    {
                        break;
                    }
                }


                for (int j = 0; j < dataGridView3.RowCount; j++)
                {

                    if (this.cboGoods.Text.Equals(dataGridView3.Rows[j].Cells["gdsname"].Value.ToString()))
                    {
                        Model.goods gm = new Model.goods();
                        gm = g.GetModel(int.Parse(this.cboGoods.SelectedValue.ToString()));
                        addname[j] = gm.goodsName;
                        addprice[j] = (decimal)gm.price;
                        addcuxiaoprice[j] = (decimal)gm.price * (decimal.Parse(gm.Promotionprice) / 100);
                        addshifoucuxiao[j] = Convert.ToBoolean(gm.Promotion);
                        addcount[j] = Convert.ToInt32(this.numericUpDown1.Text);
                        addteshuzhekou[j] = zhekou;
                        dataGridView3.Rows[j].Cells["count"].Value = int.Parse(dataGridView3.Rows[j].Cells["count"].Value.ToString()) + addcount[j];
                        if (this.button3.Text == "启用")
                        {
                            addzhekoulv[j] = (decimal.Parse(zhekoulv) / 10).ToString("F1");
                            addzongjine[j] = ((decimal)gm.price * Convert.ToInt32(this.numericUpDown1.Text) * (decimal.Parse(zhekoulv) / 100)).ToString("F1");
                            dataGridView3.Rows[j].Cells["特殊折扣"].Value = zhekou;
                            dataGridView3.Rows[j].Cells["总金额"].Value = (int)(decimal.Parse(dataGridView3.Rows[j].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView3.Rows[j].Cells["price"].Value.ToString()) * (decimal.Parse(zhekoulv) / 100));
                            dataGridView3.Rows[j].Cells["折扣率"].Value = addzhekoulv[j];
                        }
                        else
                        {

                            //addzongjine[j] = ((decimal)gm.price * this.numericUpDown1.Value * this.numericUpDown2.Value / 10).ToString("F1");


                            if (zhekou)
                            {
                                addzhekoulv[j] = Convert.ToInt32(this.numericUpDown1.Text).ToString("F1");
                                dataGridView3.Rows[j].Cells["折扣率"].Value = addzhekoulv[j];
                                dataGridView3.Rows[j].Cells["总金额"].Value = (int)(decimal.Parse(dataGridView3.Rows[j].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView3.Rows[j].Cells["price"].Value.ToString()) * (Convert.ToInt32(this.numericUpDown1.Text) / 10));
                            }
                            else
                            {
                                addzhekoulv[j] = (decimal.Parse(zhekoulv) / 10).ToString("F1");
                                dataGridView3.Rows[j].Cells["总金额"].Value = (int)(decimal.Parse(dataGridView3.Rows[j].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView3.Rows[j].Cells["price"].Value.ToString()) * (decimal.Parse(zhekoulv) / 100));
                                dataGridView3.Rows[j].Cells["折扣率"].Value = addzhekoulv[j];
                            }
                            dataGridView3.Rows[j].Cells["特殊折扣"].Value = zhekou;
                        }
                        decimal txtzongjine = 0m;
                        decimal txtzhehoujine = 0m;
                        for (int i = 0; i < dataGridView3.RowCount; i++)
                        {
                            //if (bool.Parse(dataGridView3.Rows[i].Cells["Promotion"].Value.ToString()))
                            //{
                            //    txtzongjine += decimal.Parse(dataGridView3.Rows[i].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView3.Rows[i].Cells["Promotionprice"].Value.ToString());
                            //    txtzhehoujine += decimal.Parse(dataGridView3.Rows[i].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView3.Rows[i].Cells["Promotionprice"].Value.ToString()) * (decimal.Parse(dataGridView3.Rows[i].Cells["折扣率"].Value.ToString()) / 10);

                            //}
                            //else
                            //{
                                txtzongjine += decimal.Parse(dataGridView3.Rows[i].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView3.Rows[i].Cells["price"].Value.ToString());
                                txtzhehoujine += decimal.Parse(dataGridView3.Rows[i].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView3.Rows[i].Cells["price"].Value.ToString()) * (decimal.Parse(dataGridView3.Rows[i].Cells["折扣率"].Value.ToString()) / 10);

                            //}
                        }

                        this.TxtConsume.Text = txtzongjine.ToString("F1");
                        this.TxtDiscountAmount.Text = txtzhehoujine.ToString("F1");
                        Changeprice = Convert.ToDouble(this.TxtDiscountAmount.Text);
                        if (decimal.Parse(this.TxtDiscountAmount.Text) < decimal.Parse(this.TxtBalance.Text))
                        {
                            this.TxtCardPay.Text = this.TxtDiscountAmount.Text;
                        }
                        else
                        {
                            this.TxtCardPay.Text = this.TxtBalance.Text;
                            this.TxtCrashPay.Text = (decimal.Parse(this.TxtDiscountAmount.Text) - decimal.Parse(this.TxtBalance.Text)).ToString("F1");
                        }


                        //this.TxtConsume.Text = (decimal.Parse(this.TxtConsume.Text) + (addprice[j] * addcount[j])).ToString("F1");
                        Integral = buypart(decimal.Parse(this.TxtCrashPay.Text));

                        //if (this.button3.Text == "启用")
                        //{
                        //    this.TxtDiscountAmount.Text = buyzhekou(decimal.Parse(this.TxtConsume.Text)).ToString("F1");
                        //}
                        //else
                        //{
                        //    this.TxtDiscountAmount.Text = (decimal.Parse(this.TxtConsume.Text) * (this.numericUpDown2.Value / 10)).ToString("F1");
                        //}
                        //if (decimal.Parse(this.TxtDiscountAmount.Text) < decimal.Parse(this.TxtBalance.Text))
                        //{
                        //    this.TxtCardPay.Text = this.TxtDiscountAmount.Text;
                        //}
                        //else
                        //{
                        //    this.TxtCardPay.Text = this.TxtBalance.Text;
                        //    this.TxtCrashPay.Text = (decimal.Parse(this.TxtDiscountAmount.Text) - decimal.Parse(this.TxtBalance.Text)).ToString("F1");
                        //}
                        return;
                    }

                }
                for (int j = 0; j < addname.Length; j++)
                {
                    Model.goods gm1 = new Model.goods();
                    gm1 = g.GetModel(int.Parse(this.cboGoods.SelectedValue.ToString()));
                    addname[j] = gm1.goodsName;
                    addprice[j] = (decimal)gm1.price;
                    addcuxiaoprice[j] = (decimal)gm1.price * (decimal.Parse(gm1.Promotionprice)/100);
                    addshifoucuxiao[j] = Convert.ToBoolean(gm1.Promotion);
                    addcount[j] = Convert.ToInt32(this.numericUpDown1.Text);
                    addteshuzhekou[j] = zhekou;
                    if (this.button3.Text == "启用")
                    {
                        addzhekoulv[j] = (decimal.Parse(zhekoulv) / 10).ToString("F1");
                        decimal sasa = Convert.ToDecimal(addzhekoulv[j]);
                        addzongjine[j] = (addprice[j] * addcount[j] * (Convert.ToDecimal(addzhekoulv[j]) / 10)).ToString();
                        //if (addshifoucuxiao[j] == true)
                        //{
                        //    //addzongjine[j] = (addcuxiaoprice[j] * addcount[j] * (decimal.Parse(zhekoulv) / 100)).ToString("F1");
                        //    addzongjine[j] = (addcuxiaoprice[j] * addcount[j]).ToString("F1");
                        //}
                        //else
                        //{
                        //    addzongjine[j] = (addprice[j] * addcount[j] * (decimal.Parse(zhekoulv) / 100)).ToString("F1");
                        //}
                    }
                    else
                    {
                        addzhekoulv[j] = Convert.ToInt32(this.numericUpDown1.Text).ToString("F1");
                        //addzongjine[j] = ((decimal)gm1.price * addcount[j] * Convert.ToInt32(addzhekoulv[j]) / 10).ToString("F1");
                        addzongjine[j] = (addprice[j] * addcount[j] * (Convert.ToInt32(addzhekoulv[j])/10)).ToString();
                    }


                    if (addname[j] != null)
                    {

                        string[] addgood = { addname[j], addprice[j].ToString("F1"), addcuxiaoprice[j].ToString("F1"), addshifoucuxiao[j].ToString(), addcount[j].ToString(), addteshuzhekou[j].ToString(), addzhekoulv[j], addzongjine[j] };
                        dataGridView3.Rows.Add(addgood);

                        //for (int i = 0; i < dataGridView3.Rows.Count; i++)
                        //{
                        //    //if (bool.Parse(dataGridView3.Rows[i].Cells["Promotion"].Value.ToString()))
                        //    //{
                        //        dataGridView3.Rows[i].Cells["price"].Value = "-";
                        //    //}
                        //    //else
                        //    //{
                        //        dataGridView3.Rows[i].Cells["Promotionprice"].Value = "-";
                        //    //}
                        //}


                        decimal txtzongjine = 0m;
                        decimal txtzhehoujine = 0m;
                        for (int i = 0; i < dataGridView3.RowCount; i++)
                        {
                            //if (bool.Parse(dataGridView3.Rows[i].Cells["Promotion"].Value.ToString()))
                            //{
                            //    txtzongjine += decimal.Parse(dataGridView3.Rows[i].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView3.Rows[i].Cells["Promotionprice"].Value.ToString());
                            //    txtzhehoujine += decimal.Parse(dataGridView3.Rows[i].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView3.Rows[i].Cells["Promotionprice"].Value.ToString()) * (decimal.Parse(dataGridView3.Rows[i].Cells["折扣率"].Value.ToString()) / 10);

                            //}
                            //else
                            //{
                                txtzongjine += decimal.Parse(dataGridView3.Rows[i].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView3.Rows[i].Cells["price"].Value.ToString());
                                txtzhehoujine += decimal.Parse(dataGridView3.Rows[i].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView3.Rows[i].Cells["price"].Value.ToString()) * (decimal.Parse(dataGridView3.Rows[i].Cells["折扣率"].Value.ToString()) / 10);

                            //}

                        }

                        this.TxtConsume.Text = txtzongjine.ToString("F1");
                        this.TxtDiscountAmount.Text = txtzhehoujine.ToString("F1");
                        Changeprice = Convert.ToDouble(this.TxtDiscountAmount.Text);
                        if (decimal.Parse(this.TxtDiscountAmount.Text) < decimal.Parse(this.TxtBalance.Text))
                        {
                            this.TxtCardPay.Text = this.TxtDiscountAmount.Text;
                        }
                        else
                        {
                            this.TxtCardPay.Text = this.TxtBalance.Text;
                            this.TxtCrashPay.Text = (decimal.Parse(this.TxtDiscountAmount.Text) - decimal.Parse(this.TxtBalance.Text)).ToString("F1");
                        }


                        //this.TxtConsume.Text = (decimal.Parse(this.TxtConsume.Text) + (addprice[j] * addcount[j])).ToString("F1");
                        Integral = buypart(decimal.Parse(this.TxtDiscountAmount.Text));
                        Model.operatorInfo o = new Model.operatorInfo();
                        operatorInfo ot = new operatorInfo();
                        //string passWord = this.textBox2.Text;
                        //MD5 md5 = new MD5CryptoServiceProvider();
                        //byte[] bt = Encoding.Default.GetBytes(passWord);
                        //bt = md5.ComputeHash(bt);
                        //passWord = BitConverter.ToString(bt).Replace("-", "");

                        try
                        {
                            o = ot.GetModelList(" username = '" + MainForm.Operator + "'")[0];
                        }
                        catch (Exception)
                        {

                            MessageBox.Show("折扣启用失败！");
                            return;
                        }

                        Model.roleInfo r = new Model.roleInfo();
                        roleInfo ri = new roleInfo();
                        r = ri.GetModel((int)o.roleId);
                        if (r.Specialrebate == "1")
                        {
                            for (int i = 0; i < dataGridView3.Rows.Count; i++)
                            {
                                this.dataGridView3.Rows[i].Cells["price"].ReadOnly = false;
                                this.dataGridView3.Rows[i].Cells["总金额"].ReadOnly = false;
                            }

                            this.button4.Text = "关闭改价";
                        }
                        //if (decimal.Parse(this.TxtDiscountAmount.Text) < decimal.Parse(this.TxtBalance.Text))
                        //{
                        //    this.TxtCardPay.Text = this.TxtDiscountAmount.Text;
                        //}
                        //else
                        //{
                        //    this.TxtCardPay.Text = this.TxtBalance.Text;
                        //    this.TxtCrashPay.Text = (decimal.Parse(this.TxtDiscountAmount.Text) - decimal.Parse(this.TxtBalance.Text)).ToString("F1");
                        //}
                        //if (this.button3.Text == "启用")
                        //{
                        //    this.TxtDiscountAmount.Text = buyzhekou(decimal.Parse(this.TxtConsume.Text)).ToString("F1");
                        //}
                        //else
                        //{
                        //    this.TxtDiscountAmount.Text = (decimal.Parse(this.TxtConsume.Text) * (this.numericUpDown2.Value / 10)).ToString("F1");
                        //}
                        return;
                    }

                }







            }

        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            if (dataGridView3.Rows.Count == 0)
            {
                return;
            }
            int j = dataGridView3.CurrentRow.Index;
            dataGridView3.Rows.RemoveAt(j);
            if (dataGridView3.Rows.Count == 0)
            {
                this.TxtConsume.Text = "0";
                this.TxtDiscountAmount.Text = "0";
                this.TxtCrashPay.Text = "0";
                this.TxtCardPay.Text = "0";
                return;
            }
            //decimal jiage = decimal.Parse(dataGridView3.Rows[i].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView3.Rows[i].Cells["price"].Value.ToString()) *  decimal.Parse(dataGridView3.Rows[i].Cells["折扣率"].Value.ToString());
            //this.TxtConsume.Text = (decimal.Parse(this.TxtConsume.Text) - jiage).ToString("F1");
            //TxtDiscountAmount.Text = (buyzhekou(decimal.Parse(this.TxtConsume.Text))).ToString("F1");
            decimal txtzongjine = 0m;
            decimal txtzhehoujine = 0m;
            for (int i = 0; i < dataGridView3.RowCount; i++)
            {
                txtzongjine += decimal.Parse(dataGridView3.Rows[i].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView3.Rows[i].Cells["price"].Value.ToString());
                txtzhehoujine += decimal.Parse(dataGridView3.Rows[i].Cells["count"].Value.ToString()) * decimal.Parse(dataGridView3.Rows[i].Cells["price"].Value.ToString()) * (decimal.Parse(dataGridView3.Rows[i].Cells["折扣率"].Value.ToString()) / 10);
            }

            this.TxtConsume.Text = txtzongjine.ToString("F1");
            this.TxtDiscountAmount.Text = txtzhehoujine.ToString("F1");
            if (decimal.Parse(this.TxtDiscountAmount.Text) < decimal.Parse(this.TxtBalance.Text))
            {
                this.TxtCardPay.Text = this.TxtDiscountAmount.Text;
            }
            else
            {
                this.TxtCardPay.Text = this.TxtBalance.Text;
                this.TxtCrashPay.Text = (decimal.Parse(this.TxtDiscountAmount.Text) - decimal.Parse(this.TxtBalance.Text)).ToString("F1");
            }

        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (dataGridView3.Rows.Count <= 0)
            {
                MessageBox.Show("请先添加商品");
                return;
            }

            if (this.button4.Text == "开启改价")
            {
                Model.operatorInfo o = new Model.operatorInfo();
                operatorInfo ot = new operatorInfo();
                //string passWord = this.textBox2.Text;
                //MD5 md5 = new MD5CryptoServiceProvider();
                //byte[] bt = Encoding.Default.GetBytes(passWord);
                //bt = md5.ComputeHash(bt);
                //passWord = BitConverter.ToString(bt).Replace("-", "");

                try
                {
                    o = ot.GetModelList(" username = '" + MainForm.Operator + "'")[0];
                }
                catch (Exception)
                {

                    MessageBox.Show("折扣启用失败！");
                    return;
                }

                Model.roleInfo r = new Model.roleInfo();
                roleInfo ri = new roleInfo();
                r = ri.GetModel((int)o.roleId);
                if (r.Specialrebate == "1")
                {
                    for (int i = 0; i < dataGridView3.Rows.Count; i++)
                    {
                        this.dataGridView3.Rows[i].Cells["price"].ReadOnly = false;
                        this.dataGridView3.Rows[i].Cells["总金额"].ReadOnly = false;

                    }

                    this.button4.Text = "关闭改价";
                }
                else
                {
                    specialrebate sl = new specialrebate();
                    sl.ShowDialog();
                    if (sl.aa == 1)
                    {
                        for (int i = 0; i < dataGridView3.Rows.Count; i++)
                        {
                            this.dataGridView3.Rows[i].Cells["price"].ReadOnly = false;
                            this.dataGridView3.Rows[i].Cells["总金额"].ReadOnly = false;
                        }

                        this.button4.Text = "关闭改价";
                    }
                    else
                    {
                        if (sl.aa == 3)
                        {
                            return;
                        }
                        //MessageBox.Show("特殊折扣启用未成功！原因：您并非特殊折扣管理员！");
                    }
                }


            }
            else if (this.button4.Text == "关闭改价")
            {
                this.button4.Text = "关闭改价";
                for (int i = 0; i < dataGridView3.Rows.Count; i++)
                {
                    this.dataGridView3.Rows[i].Cells["price"].ReadOnly = true;
                    this.dataGridView3.Rows[i].Cells["总金额"].ReadOnly = true;
                }
                //this.dataGridView3.CurrentRow.Cells["总金额"].ReadOnly = true;
                this.button4.Text = "开启改价";
            }
            //if (dataGridView3.Rows.Count <= 0)
            //{
            //    MessageBox.Show("请先添加商品");
            //    return;
            //}
            //if (this.button4.Text == "开启改价")
            //{
            //    this.dataGridView3.CurrentRow.Cells["总金额"].ReadOnly = false;
            //    this.button4.Text = "关闭改价";
            //}
            //else
            //{
            //    this.button4.Text = "关闭改价";
            //    this.dataGridView3.CurrentRow.Cells["总金额"].ReadOnly = true;
            //    this.button4.Text = "开启改价";
            //}
        }

        private void dataGridView3_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            decimal money = 0;

            for (int i = 0; i < dataGridView3.Rows.Count; i++)
            {
                dataGridView3.Rows[i].Cells["总金额"].Value = (int)(decimal.Parse(dataGridView3.Rows[i].Cells["price"].Value.ToString()) * decimal.Parse(dataGridView3.Rows[i].Cells["count"].Value.ToString()));
                money += decimal.Parse(dataGridView3.Rows[i].Cells["总金额"].Value.ToString());

            }

            this.TxtDiscountAmount.Text = money.ToString();
            TxtConsume.Text = money.ToString();
            if (this.TxtBalance.Text == "")
            {
                return;
            }
            if (decimal.Parse(this.TxtBalance.Text) < money)
            {
                this.TxtCardPay.Text = (decimal.Parse(this.TxtBalance.Text)).ToString();
                this.TxtCrashPay.Text = (money - decimal.Parse(TxtBalance.Text)).ToString();
            }
            else
            {
                this.TxtCardPay.Text = money.ToString();
                this.TxtCrashPay.Text = "0";
            }
        }

        private void TxtCardId_KeyPress(object sender, KeyPressEventArgs e)
        {

        }

        private void TxtCardId_KeyPress_1(object sender, KeyPressEventArgs e)
        {
            if (!(((e.KeyChar >= '0') && (e.KeyChar <= '9')) || e.KeyChar <= 31))
            {
                //if (e.KeyChar == '.')
                //{
                //    if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                //        e.Handled = true;
                //}
                //else
                e.Handled = true;
            }
            else
            {
                if (e.KeyChar <= 31)
                {
                    e.Handled = false;
                }
                else if (((TextBox)sender).Text.Trim().IndexOf('.') > -1)
                {
                    if (((TextBox)sender).Text.Trim().Substring(((TextBox)sender).Text.Trim().IndexOf('.') + 1).Length >= 4)
                        e.Handled = true;
                }
            }
        }

        private void cboGoods_TextUpdate(object sender, EventArgs e)
        {
            //List<Model.goods> goodsList = getgood();
            //cboGoods.Items.Add(goods List);
            //cboGoods.TextUpdate += (a, b) =>
            //{
            //    var input = cboGoods.Text.ToUpper();
            //    cboGoods.Items.Clear();
            //    if (string.IsNullOrWhiteSpace(input)) cboGoods.Items.Add(goodsList);
            //    else
            //    {
            //        var newList = goodsList.Where(x => x.goodsName.IndexOf(input, StringComparison.CurrentCultureIgnoreCase) != -1).ToArray();
            //        if (newList.Length <= 0)
            //        {
            //            cboGoods.Text = "";
            //            return;
            //        }
            //        cboGoods.Items.AddRange(newList);
            //    }
            //    cboGoods.Select(cboGoods.Text.Length, 0);
            //    cboGoods.DroppedDown = true;
            //    //保持鼠标指针形状  
            //    Cursor = Cursors.Default;
            //};

        }

        private void cboGoods_TextChanged(object sender, EventArgs e)
        {

        }






        private void cboGoods_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == 13)
            {

            }
        }
        public void sou()
        {

        }


        private void cboGoods_TextUpdate_1(object sender, EventArgs e)
        {
            //if (this.cboGoods.Text.Length == 0)
            //{
            //    return;
            //}
            //for (int i = 0; i < this.cboGoods.Text.Lengt  h; i++)
            //{

            //    sou();
            //}
            string goodsName = "";
            goodsName += this.cboGoods.Text;
            goods goods = new goods();
            DataTable dt = goods.GetList("goodsName like '%" + this.cboGoods.Text + "%'").Tables[0];
            if (dt.Rows.Count == 0)
            {
                return;
            }
            cboGoods.DataSource = dt;
            cboGoods.DisplayMember = "goodsName";
            cboGoods.ValueMember = "id";
            cboGoods.Cursor = Cursors.Default;
            cboGoods.DroppedDown = true;

            this.cboGoods.Text = goodsName;




        }

        private void cboGoods_TextChanged_1(object sender, EventArgs e)
        {
            // string goodsName = this.cboGoods.Text;
        }



        private void dataGridView2_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            // dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["goodcount"].Value = dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells["goodcount"].Value;
            for (int i = 0; i < dataGridView1.Rows.Count; i++)
            {
                if (dataGridView1.Rows[i].Cells["goodname"].Value == dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["goodsname"].Value)
                {
                    dataGridView1.Rows[i].Cells["goodcount"].Value = Convert.ToInt32(dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells["goodscount"].Value) + Convert.ToInt32(dataGridView1.Rows[i].Cells["goodcount"].Value);
                    break;
                }
            }

            //goods goods = new goods();
            //Model.goods goodsMode = new Model.goods();
            //goodsMode = goods.getModelGoodsIdString(dataGridView2.CurrentRow.Cells["goodid"].Value.ToString());
            //int shuliang = Convert.ToInt32(dataGridView2.CurrentRow.Cells["goodscount"].Value);
            //decimal money = Convert.ToDecimal(goodsMode.price * shuliang);
            //if (this.TxtCrashPay.Text != "0")
            //{
            //    if (Convert.ToDecimal(this.TxtCrashPay.Text) > money)
            //    {
            //        this.TxtCrashPay.Text = (Convert.ToDecimal(this.TxtCrashPay.Text) - money).ToString();
            //    }
            //    else
            //    {
            //        this.TxtCrashPay.Text = "0";
            //        this.TxtCardPay.Text = (Convert.ToDecimal(this.TxtBalance.Text) - money).ToString();
            //    }
            //}
            //else
            //{
            //    this.TxtCardPay.Text = (Convert.ToDecimal(this.TxtCardPay.Text) - money).ToString();
            //}
            //this.TxtConsume.Text = (Convert.ToDecimal(this.TxtConsume.Text) - money).ToString();





            this.dataGridView2.Rows.RemoveAt(dataGridView2.CurrentRow.Index);

        }

        private void dataGridView2_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
        {



        }

        private void dataGridView2_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
        {
            goods goods = new goods();
            Model.goods goodsMode = new Model.goods();
            decimal money = 0;
            for (int i = 0; i < dataGridView2.Rows.Count; i++)
            {
                decimal danjia = Convert.ToDecimal(goods.getModelGoodsIdString(dataGridView2.Rows[i].Cells["goodid"].Value.ToString()).price);
                int shuliang = Convert.ToInt32(dataGridView2.Rows[i].Cells["goodscount"].Value);
                money += danjia * shuliang;

            }
            decimal kaneiyue = Convert.ToDecimal(TxtBalance.Text);
            if (kaneiyue < money)
            {
                TxtCrashPay.Text = (money - kaneiyue).ToString();
            }
            else
            {
                TxtCardPay.Text = money.ToString();
            }
        }

        private void dataGridView2_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void dataGridView2_CurrentCellChanged(object sender, EventArgs e)
        {
        }

        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void btnAccount_Click_1(object sender, EventArgs e)
        {

        }

        private void btnCancel_Click_1(object sender, EventArgs e)
        {
            this.Close();
        }

        private void TxtDiscountAmount_TextChanged(object sender, EventArgs e)
        {

        }

        private void TxtDiscountAmount_TextChanged_1(object sender, EventArgs e)
        {
            
        }

        private void txtVoucherMoney_TextChanged(object sender, EventArgs e)
        {
            if (this.txtVoucherMoney.Text.Trim() == "")
            {
                this.txtVoucherMoney.Text = "0";
            }
            this.TxtDiscountAmount.Text = (Changeprice - Convert.ToDouble(this.txtVoucherMoney.Text)).ToString();
        }

        private void numericUpDown1_TextChanged(object sender, EventArgs e)
        {
            if (numericUpDown1.Text.Substring(0, 1) == "-")
            {
                ZG_member.BLL.operatorInfo opera = new ZG_member.BLL.operatorInfo();
                ZG_member.Model.operatorInfo operaMode = new ZG_member.Model.operatorInfo();
                ZG_member.BLL.roleInfo role = new ZG_member.BLL.roleInfo();
                ZG_member.Model.roleInfo roleMode = new ZG_member.Model.roleInfo();
                operaMode = opera.GetModelList("username='" + MainForm.Operator + "'")[0];
                roleMode = role.GetModel(Convert.ToInt32(operaMode.roleId));
                if (roleMode.roleInfo1[37].ToString() == "0")
                {
                    MessageBox.Show("您没有冲红权限！");
                    numericUpDown1.Text = "1";
                    return;
                }



            }
        }

        private void comboBox1_TextChanged(object sender, EventArgs e)
        {
            try
            {
                ZG_member.BLL.CourseStage course = new ZG_member.BLL.CourseStage();
                ZG_member.Model.CourseStage courseMod = new ZG_member.Model.CourseStage();
                courseMod = course.GetModel(comboBox1.Text);
                this.textBox1.Text = courseMod.StageContent;
            }
            catch (Exception)
            {
                
                
            }
     
        }

   

    




















    }
}
